Delete Bookmarked text

L

Legal Learning

I have a document that has tons of bookmarked text. They are, at least,
named A1, A2, A3 etc. or B1, B2, B3 etc. all the way through J. Some alpa
have 5 (for example: A1, A2, A3, A4, A5 and some have less or more B1, B2
and C1, C2, C3.

How can I programmatically, delete the bookmarked text if the bookmarks are
named as such? This would be quite a chore manually as there are tons of
them. thanks for any help
 
M

macropod

Hi Legal Learning,

Do you want to delete all the bookmarks in the document, or just the two-character alphanumeric ones?
 
L

Legal Learning

Hi,

I need to delete some of them but may not be all of them. I need to have a
choice. So, I would need a different procedure for A's and B's. I would
also need to count them first before trying to delete them. Does this make
any sense?
--
CLG


macropod said:
Hi Legal Learning,

Do you want to delete all the bookmarks in the document, or just the two-character alphanumeric ones?

--
Cheers
macropod
[Microsoft MVP - Word]


Legal Learning said:
I have a document that has tons of bookmarked text. They are, at least,
named A1, A2, A3 etc. or B1, B2, B3 etc. all the way through J. Some alpa
have 5 (for example: A1, A2, A3, A4, A5 and some have less or more B1, B2
and C1, C2, C3.

How can I programmatically, delete the bookmarked text if the bookmarks are
named as such? This would be quite a chore manually as there are tons of
them. thanks for any help
 
G

Greg Maxey

Perhaps something like this:

Sub ScratchMacro()
Dim oBMs As Bookmarks
Dim i As Long
Dim oBM As Bookmark
Set oBMs = ActiveDocument.Bookmarks
'Count them first
For Each oBM In oBMs
If oBM.Name Like "[A-J]#" Then
i = i + 1
End If
Next oBM
MsgBox "There are " & i & " bookmarks with the pattern specified"
'Selectively delete
For Each oBM In oBMs
If oBM.Name Like "[A-J]#" Then
oBM.Range.Select
If MsgBox("Do you want to delete this Bookmark?", vbQuestion + vbYesNo,
"Delete " & oBM.Name) = vbYes Then
oBM.Range.Delete
End If
End If
Next oBM
End Sub


Legal said:
Hi,

I need to delete some of them but may not be all of them. I need to
have a choice. So, I would need a different procedure for A's and
B's. I would also need to count them first before trying to delete
them. Does this make any sense?
Hi Legal Learning,

Do you want to delete all the bookmarks in the document, or just the
two-character alphanumeric ones?

--
Cheers
macropod
[Microsoft MVP - Word]


Legal Learning said:
I have a document that has tons of bookmarked text. They are, at
least, named A1, A2, A3 etc. or B1, B2, B3 etc. all the way
through J. Some alpa have 5 (for example: A1, A2, A3, A4, A5 and
some have less or more B1, B2 and C1, C2, C3.

How can I programmatically, delete the bookmarked text if the
bookmarks are named as such? This would be quite a chore manually
as there are tons of them. thanks for any help
 
L

Legal Learning

Greg! Wow! Thanks so much. I sure admire vba brains like yours. Don't
think I will ever be that good. Take care and thanks again!!!
--
CLG


Greg Maxey said:
Perhaps something like this:

Sub ScratchMacro()
Dim oBMs As Bookmarks
Dim i As Long
Dim oBM As Bookmark
Set oBMs = ActiveDocument.Bookmarks
'Count them first
For Each oBM In oBMs
If oBM.Name Like "[A-J]#" Then
i = i + 1
End If
Next oBM
MsgBox "There are " & i & " bookmarks with the pattern specified"
'Selectively delete
For Each oBM In oBMs
If oBM.Name Like "[A-J]#" Then
oBM.Range.Select
If MsgBox("Do you want to delete this Bookmark?", vbQuestion + vbYesNo,
"Delete " & oBM.Name) = vbYes Then
oBM.Range.Delete
End If
End If
Next oBM
End Sub


Legal said:
Hi,

I need to delete some of them but may not be all of them. I need to
have a choice. So, I would need a different procedure for A's and
B's. I would also need to count them first before trying to delete
them. Does this make any sense?
Hi Legal Learning,

Do you want to delete all the bookmarks in the document, or just the
two-character alphanumeric ones?

--
Cheers
macropod
[Microsoft MVP - Word]


message I have a document that has tons of bookmarked text. They are, at
least, named A1, A2, A3 etc. or B1, B2, B3 etc. all the way
through J. Some alpa have 5 (for example: A1, A2, A3, A4, A5 and
some have less or more B1, B2 and C1, C2, C3.

How can I programmatically, delete the bookmarked text if the
bookmarks are named as such? This would be quite a chore manually
as there are tons of them. thanks for any help
 

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