Word的ActiveX控件。选择文字和图片

时间:2013-08-07 11:09:31

标签: matlab ms-word activex word-vba office-interop

这是我到目前为止所做的:

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;

如何选择之前输入的文字(如“Big Finale”)进行编辑,或选择我粘贴选区的图形。粘贴命令以便为图像制作标题?

1 个答案:

答案 0 :(得分:3)

VBA for MS Word的可能解决方案:

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

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

查找inlineshape的替代解决方案是使用.Find.Execute method并使用以下设置:

Selection.Find.Execute FindText:="/", Wrap:=wdWrapAlways, MatchWildcards:=True