Delete bookmark content

B

Bala

Hi

My word doc contain nearly 200 pages and and have nearly 500 bookmarks. From
vb the user will pick up the bookmarks. so after that i need to remove those
bookmark contents. so i am using the below code. its seems executing fine
with bookmark delete code. finally look at the doc, the content is not
deleted. i dont know where am i doing mistake. can anyone please look at the
code and let me know if anymistake on the code.

thanks
bala

code

Dim objWord As Object
Dim objwordtarget As Object

Set objWord = CreateObject("Word.application")
objWord.Documents.Open ("C:\AMAImpairment\AIRReport1.doc")



objWord.ActiveDocument.Repaginate
objWord.Application.Browser.Target = wdBrowsePage
objWord.ActiveDocument.Select
Selection.MoveStart Unit:=wdCharacter, Count:=1
objWord.Application.Browser.Target = wdBrowsePage

'************************************************

Dim cntfirst As Integer
cntfirst = 1
Dim blnfind As Boolean

For J = 0 To UBound(DefaultBkms)
For i = 0 To UBound(docPageNo)
If UCase(DefaultBkms(J)) = UCase(docPageNo(i)) Then
blnfind = True
Exit For
Else
blnfind = False
End If
Next
If blnfind = False Then
If objWord.ActiveDocument.Bookmarks.Exists(DefaultBkms(J)) =
True Then
objWord.ActiveDocument.Bookmarks(DefaultBkms(J)).Delete
End If
End If
blnfind = False
Next
objWord.ActiveDocument.Close wdSaveChanges
objWord.Quit
Set objWord = Nothing
 
B

Bala

No problem. got it. this code will do.

If objWord.ActiveDocument.Bookmarks.Exists(DefaultBkms(J)) = True Then
objWord.ActiveDocument.Bookmarks(DefaultBkms(J)).Select
objWord.ActiveDocument.Bookmarks(DefaultBkms(J)).Delete
objWord.Selection.Delete
End If
 

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