How do I edit a the contents of bookmark without deleting the book

J

Jane C

I have a template (Word 2003) that contains bookmarks. The contents of the
bookmarks are used in other places of the document, and for some conditional
formatting (watermarks). My problem is that unless you are a reasonably
experienced Word user who has there bookmarks showing, it is very easy to
delete the bookmark entirely. Similarly, if you're trying to edit part of the
contents, you can end up with only some of the new contents inside the
bookmark. Is there any smart way of setting up your bookmark to lower this
risk?

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

Pesach Shelnitz

Hi Jane,

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

Graham Mayor

Given your examples, I wouldn't use bookmarks for this function. I would use
instead docvariables, the contents of which you can place with docvariable
fields in place of the bookmarks and reference fields. How you update the
information in the docvariables rather depends on how the document is used,
but as a simple option you could use something like the following which will
prompt for the version and status and update the fields in the document.
http://www.gmayor.com/installing_macro.htm . Input boxes as used here are
not as elegant as a userform but are easier to convey as a listing

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

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

Jane said:
I have a template (Word 2003) that contains bookmarks. The contents
of the bookmarks are used in other places of the document, and for
some conditional formatting (watermarks). My problem is that unless
you are a reasonably experienced Word user who has there bookmarks
showing, it is very easy to delete the bookmark entirely. Similarly,
if you're trying to edit part of the contents, you can end up with
only some of the new contents inside the bookmark. Is there any
smart way of setting up your bookmark to lower this risk?

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

Suzanne S. Barnhill

There is an article at
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm that may
also be helpful.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

Pesach Shelnitz said:
Hi Jane,

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


Jane C said:
I have a template (Word 2003) that contains bookmarks. The contents of
the
bookmarks are used in other places of the document, and for some
conditional
formatting (watermarks). My problem is that unless you are a reasonably
experienced Word user who has there bookmarks showing, it is very easy to
delete the bookmark entirely. Similarly, if you're trying to edit part of
the
contents, you can end up with only some of the new contents inside the
bookmark. Is there any smart way of setting up your bookmark to lower
this
risk?

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.
 

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