0
votes

Im trying to execute the following in a matlab file :

hdlActiveX = actxserver('Word.Application');
hdlActiveX.Selection.GoTo(what, which, count, name);

in order to go to a certain place in the word document, and after it to write something in it, at the place where the bookmark is.

In the above code sample, the GoTo parameters are :

what = -1; % 'wdGoToBookmark'
which = 1; % 'wdGoToAbsolute'
count = 1;
name = 'myBookmark';

Further, even though the bookmark is available, I only get:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: The bookmark is not available.
Help File: wdmain11.chm
Help Context ID: 6005

If you could help me find the answer of the following questions:

1) (main question) how can I find out, what is exactly the problem ? i.e. how should I write the code in order to function ?

2) (minor question) where can I found, the values of the whats, and whichs (e.g. wdGotoBookmark is -1) ?

Thank you in advance,

3
There is not enough information on your prior actions in order to reproduce the problem - Andrey Rubshtein
What are you trying to do exactly? Please edit the question with more information. I'd upvote. - yuk
I edited the question. Im trying to go to a certain place in the word document, in order to write something in it, at the place where the bookmark is. - HeinrichStack

3 Answers

0
votes

I would recommend to test the code in VBA editor in Word first. Then convert it into MATLAB (which shouldn't be difficult).

Once you are in Word press Alt-F11 to start VBA editor. To find the values for constants go to Object Browser (through View menu or press F2) and on the left column find WdGoToItem. On the right you will see different values, selecting one will give you its values in the bottom panel.

I can reproduce the error but cannot help you since I'm not sure what you are trying to do. Please give more details. I think you cannot use Selection object, you will probably need ActiveDocument. Read the help and reference documentation in VBA editor, it's pretty good.

Here is online MSDN documentation to Word VBA.

0
votes

I am not sure what your code does, but if your are trying to find a bookmark using automation server you could dohdlActiveX.ActiveDocument.BookMark('bookmarkname').Select which will bring you to the bookmark in the active document. Your code does not have an ActiveDocument therefore it may not work.

0
votes

In order to select a bookmark over ActiveX in the above example, I did this:

hdlActiveX.ActiveDocument.Bookmarks.Item('myBookmark').Select

Than i could add my text, where I wanted :

hdlActiveX.Selection.TypeText('myText');

Thank you very much everyone for the tips !