PDA

View Full Version : Solved: Deleteing unused word bookmarks



rob0923
08-11-2009, 12:10 PM
Hi,

I am pushing information from excel to word bookmarks, but I was wondering if there was a way to delete any bookmarks that are unused?


'Place into bookmark if Excel name match Word bookmark
If objDoc.Bookmarks.Exists(ExlNm.Name) Then
objDoc.Bookmarks(ExlNm.Name).Range.Text = ExlNm.Value
End If
Next ExlNm



After this statement is it possible to remove any unused word bookmarks


If not objDoc.Bookmarks.Exists(ExlNm.Name) Then
del / remove objDoc.Bookmarks
End If
Next ExlNm


Thanks in advance!

rob0923
08-11-2009, 12:18 PM
Also if possible to also delete any end paragraphs with the word bookmark.

Thanks!

macropod
08-11-2009, 03:57 PM
Hi Rob,

Try something based on:
Dim oPara As Paragraph, oBkMrk As Bookmark
With objDoc
For Each oPara In .Paragraphs
If oPara.Range.Text = vbCr Then oPara.Range.Delete
Next
.Bookmarks.ShowHidden = True
For Each oBkMrk In .Bookmarks
If .Bookmarks(oBkMrk).Empty = True Then oBkMrk.Delete
Next
.Bookmarks.ShowHidden = False
End With

rob0923
08-16-2009, 05:12 PM
Sorry for the late response, thanks macropod. I will test it out asap.

Thanks again!