Bookmarks

E

EllenM

Hello, I am trying to create a macro to work with a Word template that
contains placeholders for text that will change from document to document
based on this template. I discovered bookmarks as a possible solution but
have no clue how to use them. Ultimately, I would like my macro to prompt the
user to enter data into a userform (data that will go into these bookmarks).
As an initial step, I am trying to run the following code which I presume
inserts bookmarks in a Word document but I get a runtime error 5941. Any
suggestions? Thanks



Dim bmRange As Range

Set bmRange = ActiveDocument.Bookmarks("myBookmark").Range

bmRange.Text = "Inserted Text"

ActiveDocument.Bookmarks.Add _
Name:="myBookmark", _
Range:=bmRange

Thanks for your help,
Ellen
 
G

Graham Mayor

You may find it simpler to insert the bookmarks in the template manually
then use the command similar to

Selection.GoTo What:=wdGoToBookmark, Name:="myBookmark"

to set the insertion point at the bookmark(s). Then at its most basic, you
could use an input box to get the text eg

Dim strText As String
strText = InputBox("Enter Text")
With Selection
.GoTo What:=wdGoToBookmark, Name:="myBookmark"
.TypeText strText
End With

The basic principle is similar if you collect the data with a userform -
Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm

or

You may find it simpler still to use macrobutton fields as placeholders -
http://www.gmayor.com/Macrobutton.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
E

EllenM

Thanks, Graham. You were quite helpful.

Graham Mayor said:
You may find it simpler to insert the bookmarks in the template manually
then use the command similar to

Selection.GoTo What:=wdGoToBookmark, Name:="myBookmark"

to set the insertion point at the bookmark(s). Then at its most basic, you
could use an input box to get the text eg

Dim strText As String
strText = InputBox("Enter Text")
With Selection
.GoTo What:=wdGoToBookmark, Name:="myBookmark"
.TypeText strText
End With

The basic principle is similar if you collect the data with a userform -
Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm

or

You may find it simpler still to use macrobutton fields as placeholders -
http://www.gmayor.com/Macrobutton.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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