Autotext

R

rlampky

I know this is very basic, but I cant find where I wrote this prior.

I have a foor populated with bookmarks. I want to insert an autotext entry
at one of the mookmarks via a macro.

I know how to select the specific bookmark in my active document, but keep
createing erros when I try to insert the autotext at the bookmark.

THANKS in advance
 
P

Peter Hewett

Hi rlampky

Use this procedure, it will inserted the named AutoText entry at the specified
bookmark:


Public Sub InsertAutoText(ByVal strAutoTextName As String, _
ByVal strBookmarkName As String)
Dim tplAttached As Word.Template
Dim rngLocation As Word.Range

' Insert specified autotext at the bookmarked location
' and then recreate the bookmark
Set tplAttached = ActiveDocument.AttachedTemplate
Set rngLocation = ActiveDocument.Bookmarks(strBookmarkName).Range
Set rngLocation = _
tplAttached.AutoTextEntries(strAutoTextName).Insert(rngLocation, True)
ActiveDocument.Bookmarks.Add strBookmarkName, rngLocation
End Sub

Call it like this:

InsertAutoText "AutoTextName", "BookmarkName"

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top