2009-07-14 29 views
0

我正在尝试将VBA宏迁移到VSTO(Word)。在宏我做了以下在当前选定的位置插入自动图文集:VSTO for Word和自动图文集

ActiveDocument.AttachedTemplate.AutoTextEntries("agenda#").Insert where:=Selection.Range, RichText:=True 

现在我已经添加了一个富文本contentconrtol(XYZ)的文件,但我无法找到了解如何插入自动图文集。

我在寻找类似:

Globals.ThisDocument.XYZ.insertAutotext("agenda#") 

有谁知道一个简单的方法来做到这一点?

回答

0

试试这个:

Word.Template template = (Word.Template)this.Application.ActiveDocument.get_AttachedTemplate(); 

object agendaObj = "agenda#"; 
object richText = true; 

Word.AutoTextEntry agenda = template.AutoTextEntries.get_Item(ref agendaObj); 
agenda.Insert(XYZ.range, ref richText);