Insert a Word AutoText Entry at a Bookmark Using VBA
Question details
Insert a named AutoText entry at a Word bookmark using VBA while preserving the bookmark.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- A macro needs to insert an AutoText entry stored in a specific template at a named bookmark.
- Observed behavior
- Calling InsertAutoText on the selection may fail when Word is not searching the template that contains the entry, and insertion can replace the original bookmark.
In Word, open the document and use Insert > Bookmark to confirm the bookmark name. Identify the template containing the exact AutoText entry name, and enable macros only if the document and code are trusted.
Insert AutoText from its source template and recreate the bookmark
Use this method when you know the bookmark name, AutoText name, and template that stores the entry.
The macro inserts the entry at the bookmark range using the specified template. It then adds the bookmark again around the inserted range.
In the document, type the exact AutoText name and press F3 to test whether Word can insert it manually. If it does not insert, check which template contains the entry.
Open Developer > Visual Basic, choose Insert > Module, and paste: Sub AutoTextToBM(strBookmark As String, sourceTemplate As Template, strAutoText As String) Dim rng As Range On Error GoTo ExitHandler Set rng = ActiveDocument.Bookmarks(strBookmark).Range Set rng = sourceTemplate.AutoTextEntries(strAutoText).Insert(Where:=rng, RichText:=True) ActiveDocument.Bookmarks.Add Name:=strBookmark, Range:=rng ExitHandler: End Sub
In the same module, add a calling macro for an entry stored in the document's attached template: Sub InsertMyAutoText() AutoTextToBM "SubAttorneysToAct", ActiveDocument.AttachedTemplate, "POASattJointlyOrSeverally" End Sub Replace the bookmark and AutoText names with your exact names. If the entry is stored elsewhere, pass the Template object for that template instead.
Place the cursor inside InsertMyAutoText in the VBA editor and select Run > Run Sub/UserForm. Return to Word and use Insert > Bookmark to confirm that the bookmark still exists around the inserted content.
Edit Word documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for an easier move between office suites. The Word VBA procedure above is specific to Microsoft Word; WPS is not presented as a fix for it.

Frequently Asked Questions
Why does the macro insert nothing?
The bookmark or AutoText entry may not exist under the supplied name, or the entry may be in a different template. Check Insert > Bookmark and pass the template that contains the entry. The sample error handler exits without displaying an error.
How can I test an AutoText entry before running the macro?
Type the exact entry name in Word and press F3. If it does not insert, check that the entry is available from the relevant template; the macro can reference that template directly.
Why does the macro add the bookmark again?
Inserting content can replace the original bookmark range. Bookmarks.Add recreates the named bookmark using the range returned by AutoTextEntries.Insert.
Can I use an AutoText entry from a template other than the attached template?
Yes. Pass the Template object for the template containing the entry as the sourceTemplate argument instead of ActiveDocument.AttachedTemplate.




