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.

Clearing/Resetting document bookmarks via the UserForm

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hillsider - 12 Jun 2007 14:43 GMT
Great tutorial, I just finished and my UserForm works (once).  The
fields from the UserForm are placed into the document at the bookmarks
using the .InsertBefore feature.  Now I would like to add a 'reset'
button to clear the document (after printing) so it can be filled out
again. If I use the .InsertBefore " ", it just adds a space before my
previous entry.  I tried using .Delete but that deleted my bookmark.
  Please help.

Cheers then,
Hillsider
hillsider - 12 Jun 2007 21:04 GMT
UPDATE:  I figured it out!

'macro to update bookmarks
  Sub UpdateBookmark(BookmarkToUpdate  As String, TextToUse  As String)
    Dim BMRange As Range
    Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
    BMRange.Text = TextToUse
    ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End Sub
'called like this:
UpdateBookmark "NameOfBookMark", "String to insert"

cheers then,

hillsider

> Great tutorial, I just finished and my UserForm works (once).  The
> fields from the UserForm are placed into the document at the bookmarks
[quoted text clipped - 6 lines]
> Cheers then,
> Hillsider
Doug Robbins - Word MVP - 12 Jun 2007 21:06 GMT
The normal procedure would be to create a new document from the template
each time.  To do what you want to do however, it would be better to used
document variables and DOCVARIABLE fields instead of bookmarks.

In the code behind the user form, you would use

With ActiveDocument
   .Variables("varname1").Value = [somecontrolvalue]
   .Variables("varname2").Value = [someothercontrolvalue]
   etc
   .Range.Fields.Update
End With

and in the template, where you want [somecontrolvalue] to appear, you would
have a { DOCVARIABLE varname1 } field, etc.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Great tutorial, I just finished and my UserForm works (once).  The fields
> from the UserForm are placed into the document at the bookmarks using the
[quoted text clipped - 6 lines]
> Cheers then,
> Hillsider
 
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.