Examples from my document, where [] indicates a bookmark:
Document Status: [Draft]
Document Version: [0.1]
If you double-click on Draft and type "Final", you will delete the bookmark.
If you place the cursor after the decimal point and hit delete then type 2
(i.e. to change 0.1 to 0.2), you will only have "0." inside the bookmark.
When you create a bookmark, you can create it for the cursor location
(insertion point) or for selected text. When you create a bookmark for the
cursor location, the bookmark has no contents, and contents can be inserted
into it only programmatically. When a bookmark is created for selected text,
you can change the contents of the bookmark, but, as you have discovered, you
have to be careful to maintain the boundaries of the bookmarked text and to
avoid deleting the bookmark.
To clearly see the boundaries of bookmarked text, you can use the UI to go
to the bookmark (see
http://office.microsoft.com/en-us/word/HP052348811033.aspx?pid=CH061049411033
for instructions). In this case, the contents of the bookmark are
highlighted. Alternatively, you can configure the Word options to display
nonprinting brackets around all of your bookmarks or an I-beam at bookmarks
created at the cursor location (see
http://office.microsoft.com/en-us/word/HP051894731033.aspx?pid=CH061049411033
for instructions).
I have found that a safe way to replace the contents of a bookmark is to use
one of the above methods to clearly show the boundaries of the bookmarked
text and then to insert the new text inside the old text and delete the
unwanted old text after the new text is inserted.
--
Hope this helps,
Pesach Shelnitz
For the basics, see Word MVP FAQ - Userforms
http://word.mvps.org/FAQs/Userforms.htm
for a more in depth explanation, see
http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm
A similar method could be used to replace the content of bookmarks, but as
you acknowledge bookmarks are somewhar less robust than fields.
Sub SetStatus()
Dim oVars As Variables
Dim vVar As Variant
Dim bExists As Boolean
Dim iVersion As Integer
Dim sStatus As String
Dim oStory As Range
Set oVars = ActiveDocument.Variables
sStatus = UCase(InputBox("Is this the final version Y/N?", _
"Status", "N"))
bExists = False
For Each vVar In oVars
If vVar.name = "varVersion" Then
bExists = True
Exit For
End If
Next vVar
If bExists = False Then
oVars("varVersion").Value = 0
End If
iVersion = oVars("varVersion").Value
iVersion = InputBox("Enter version number", _
"Version", iVersion + 1)
oVars("varVersion").Value = iVersion
If sStatus = "N" Then
oVars("varStatus").Value = "Draft"
Else
oVars("varStatus").Value = "Final"
End If
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
"Pesach Shelnitz" <pesach18(AT)hotmail.com> wrote in message
news:FDA003F5-61F1-4750...@microsoft.com...