Jay
Thu Jul 17 07:01:05 PDT 2008
Capitalleaf wrote:
> I have multiple bookmarks in a document that all begin with "ABC...".
> The "..." can be any combination of letters and numbers at varying
> lenghts. Is there a way to search for all bookmarks within the
> document that begin with "ABC" using VBA? Once found, the bookmark
> will be deleted. I'm using Word 2007. Please let me know if more
> info is needed. Thank you!!
You need to iterate through the whole collection, testing each bookmark to
see whether its name matches your criterion.
Here's sample code:
Sub demo()
Dim bk As Bookmark
For Each bk In ActiveDocument.Bookmarks
With bk
If Len(.Name) > 3 Then
If UCase(Left(.Name, 3)) = "ABC" Then
.Range.Delete
End If
End If
End With
Next
End Sub
If you meant that you wanted to remove the bookmark but leave the text
that's inside it, then change .Range.Delete to just .Delete.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.