views:

210

answers:

1

I'm trying to migrate a VBA macro to VSTO (Word). In the macro I did the following to insert an Autotext at the currently selected Position:

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

Now I've added a rich-text-contentconrtol (XYZ) to the document, but I'm not able to find out how to insert the Autotext.

I'm looking for something like:

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

Does anybody know of an easy way to do this?

A: 

Try this:

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