ActiveX control of Word. Select text and images

核能气质少年 提交于 2019-12-12 04:48:04

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/18101841/activex-control-of-word-select-text-and-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!