0

This is what I have done so far:

word = actxserver('Word.Application');

document = word.documents.Open('C:\Documents and Settings\kz7213\Desktop\Test.docx');

selection = word.Selection;

selection.TypeText('Big Finale'); 
selection.Style='Heading 1'; 
selection.TypeParagraph;

FIG1 = figure('Visible','off'); plot([1 2 3 4 5],[4 1 3 5 7]);

print -dmeta

selection.Paste; 

selection.Style='Heading 1';

selection.InsertCaption('Figure','Test figure 1'); %Not working
selection.Style='CaptionStyle';

selection.TypeParagraph;

How can I select previous entered text such as "Big Finale" to edit it, or select the figure I pasted with the selection. Paste command in order to make a caption for the image?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

3

Possible solution in VBA for MS Word:

'to find a text
    Selection.Find.Execute FindText:="Big Finale", Wrap:=wdWrapAlways

'to select inline shape
    ActiveDocument.InlineShapes(1).Select

Alternative solution to find a inlineshape(s) is to use .Find.Execute method with the following settings:

Selection.Find.Execute FindText:="/", Wrap:=wdWrapAlways, MatchWildcards:=True
Kazimierz Jawor
  • 18,861
  • 7
  • 35
  • 55
  • in MATLAB that would be: `selection.Find.Execute('Big Finale',[],[],[],[],[],[],1)` for the first one (where `1` is the underlying value of the enum `wdWrapAlways` for `Wrap` option). Note that we had to specify empty values for the other optional arguments of [`Find.Execute`](http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.find.execute.aspx), since MATLAB only supports positional arguments – Amro Aug 07 '13 at 12:36
  • Second one is: `document.InlineShapes.Item(1).Select` while the last one: `selection.Find.Execute('/',[],[],true,[],[],[],1)` – Amro Aug 07 '13 at 12:46
  • small correction: `Wrap` should be one of [`WdFindWrap`](http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdfindwrap.aspx) constants, which is `wdFindContinue` in this case (also represented by `1`) – Amro Aug 07 '13 at 13:02