2009-07-14 58 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);