Group:  Microsoft Word ยป microsoft.public.word.vba.userforms
Thread: Clearing/Resetting document bookmarks via the UserForm

Clearing/Resetting document bookmarks via the UserForm
hillsider <hillsider[ at ]comcast.net> 6/12/2007 1:43:46 PM
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
Re: Clearing/Resetting document bookmarks via the UserForm
hillsider <hillsider[ at ]comcast.net> 6/12/2007 8:04:37 PM
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


hillsider wrote:
[Quoted Text]
> 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
Re: Clearing/Resetting document bookmarks via the UserForm
"Doug Robbins - Word MVP" <dkr[ at ]REMOVECAPSmvps.org> 6/12/2007 8:06:34 PM
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.

--
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

"hillsider" <hillsider[ at ]comcast.net> wrote in message
news:%23hCd8ePrHHA.532[ at ]TK2MSFTNGP06.phx.gbl...
[Quoted Text]
> 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


Home | Search | Terms | Imprint
Newsgroups Reader