【问题标题】:VSTO for Word and Autotext用于 Word 和自动文本的 VSTO
【发布时间】:2015-02-24 03:19:03
【问题描述】:

我正在尝试将 VBA 宏迁移到 VSTO (Word)。在宏中,我执行以下操作以在当前选定的位置插入自动文本:

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

现在我已在文档中添加了富文本内容控制 (XYZ),但我不知道如何插入自动文本。

我正在寻找类似的东西:

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

有人知道一个简单的方法吗?

【问题讨论】:

    标签: vba ms-word migration vsto


    【解决方案1】:

    试试这个:

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-25
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多