Predefined bookmarks cannot be modified?

R

Robert

I have a template with a dialog box. If a checkbox is not
checked, the line containing the bookmark is deleted when
the dialog box is closed, like so:
If UserForm1.CheckBox1.Value = False Then
ActiveDocument.Bookmarks("b1").Select
ActiveDocument.Bookmarks("\line").Delete
End If
I tried using Documents("template.dot") instead, and that
didn't work either.
How do you delete a line with a bookmark in it? I am using
the bookmark to identify the line. Should I be doing this
some other way? Thanks.
 
J

Jonathan West

Hi Robert,

This line

ActiveDocument.Bookmarks("b1").Delete

deletes a bookmark.

This line

ActiveDocument.Bookmarks("b1").Range.Delete

deletes the text marked by a bookmark.

You cannot delete predefined bookmarks, but yoiu can delete the text marked
by them, so you can do this

ActiveDocument.Bookmarks("\line").Range.Delete
 
I

Ian

Robert said:
How do you delete a line with a bookmark in it? I am using
the bookmark to identify the line. Should I be doing this
some other way? Thanks.

Robert, this may help. You asked about how to delete a line with a
bookmark in it, where the bookmark identifies the line. As an
alternative, you could define the *whole* line as a bookmark, and then
delete the bookmark:

~~~~~~~~~~~~~~~~~~
Selection.GoTo What:=wdGoToBookmark, Name:=("bookmarkname")
Selection.Cut

~~~~~~~~~~~~~~~~~~

Note, however, that after you have deleted the bookmark, you cannot
refer to it again.

Also, the "line" could, of course, be any amount of text. I use the
above code in a template that deletes many pages of text, where all the
pages are defined by one bookmark. Very useful for removing unwanted
clauses in a legal agreement, for example.
 

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