Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EllenM - 05 Jun 2007 12:04 GMT
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
Graham Mayor - 05 Jun 2007 12:29 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 17 lines]
> Thanks for your help,
> Ellen
EllenM - 05 Jun 2007 19:50 GMT
Thanks, Graham.  You were quite helpful.

> You may find it simpler to insert the bookmarks in the template manually
> then use the command similar to
[quoted text clipped - 41 lines]
> > Thanks for your help,
> > Ellen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.