Delete Current Bookmark

B

Bill Foley

Hey Gang, back with another question:

Word XP

I have a bookmarked document that I am trying to manipulate various
bookmarks to create subdocuments. I have code that bookmarks selected
paragraphs with incremented bookmark names, and it works fine.

I also have code that goes through and deletes all bookmarks in the
document, if needed.

What I can't seem to get is to delete the current bookmark. For example, if
a user selects text and assigns a bookmark to it (bma_8, for example). I
know they can select the text, click "Insert", "Bookmarks", click the
"Delete" button and that bookmark is deleted. I also know that you can
select a bookmarked set of text and assign a different bookmark to it
(bmb_5, for example). But I am trying to create a macro that does the
following (after a selection of bookmarked text has been made):

- Determine the bookmark name, then delete that bookmark (not the text, just
the bookmark itself).

Using the recorder, simply includes the bookmark name of the selected text.
I want it to be variable so whatever bookmark is selected, it can be
deleted.

The concept of the code I need (which I obviously can't get to work) is
below:

========

Sub DeleteCurrentBookmark()

Dim Mybm As Bookmark

With Selection.Bookmarks
If .Count = 1 Then
Set Mybm = .Item(1).Name
ActiveDocument.Bookmarks(Mybm).Delete
End If
End With

End Sub

========

TIA!
 
B

Bill Foley

Sheesh, what a moron! And to think I almost got that round peg in that
square hole!

THANKS!
 

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