Code covered by the BSD License  

Highlights from
Simulink to MS Word Easy Navigation

image thumbnail

Simulink to MS Word Easy Navigation

by

 

18 May 2012 (Updated )

Open a Word document at a specific bookmark location by a double click in a Simulink Model

gotoBookmark(document,bookmark)
function gotoBookmark(document,bookmark)

% get the current running Word COM server or open a new one
try 
    hComServer = actxGetRunningServer('Word.Application');
catch err
    hComServer = actxserver('Word.Application');
end
hComServer.Visible = 1;

% get the absolute path name of the document
filepath = document;
if isempty(intersect(':',filepath))
    filepath = [pwd '\' filepath];
end

% check if the document is already open
isOpened = false;
for i=1:hComServer.Documents.Count
    name = hComServer.Documents.Item(i).Name;
    path = hComServer.Documents.Item(i).Path;
    fullname = [path '\' name];
    if strcmp(filepath,fullname)
        isOpened = true;
    end
end

% otherwise open it
if ~isOpened
    try
        hComServer.Documents.Open(filepath)	;
    catch err
        error(err.message);
    end
end

% go to the bookmark
try
    hComServer.Documents.Item(filepath).bookmarks.Item(bookmark).Select;
    for i=1:10
        hComServer.Activate;
    end
catch err
    error(err.message);
end

end

Contact us