delete all bookmarks in file

T

Tony Logan

Can a macro delete all bookmarks in a file? I want to be able to delete all
of them without knowing in advance how many there are, since the number will
vary from file to file.

I'm using Word XP.
 
J

Jonathan West

Tony Logan said:
Can a macro delete all bookmarks in a file? I want to be able to delete
all
of them without knowing in advance how many there are, since the number
will
vary from file to file.

I'm using Word XP.

This will do the needful

Dim n as Long
For n = 1 to ActiveDocument.Bookmarks.Count
ActiveDocument.Bookmarks(1).Delete
Next n
 
V

Vince

Ha ha! Typo!

Dim n as Long
For n = 1 to ActiveDocument.Bookmarks.Count
ActiveDocument.Bookmarks(n).Delete
Next n
 
J

Jonathan West

Vince said:
Ha ha! Typo!

Dim n as Long
For n = 1 to ActiveDocument.Bookmarks.Count
ActiveDocument.Bookmarks(n).Delete
Next n

No typo. You try it my way and then your way, and see which works.
 
J

Jezebel

Vince, you should have tried it first, before proving so gleeefully to the
world that you're an obnoxious fuckwit.
 
J

Jonas

when I use this method for deleting all bookmarks, for some reason the var n
only goes up to half of the ActiveDocument.Bookmarks.Count total and then
exits the loop. If I try to force the loop to calculate over half, it shows
the Bookmarks(n) to be invalid. anybody have any clues?

Thanks alot,
J.
 
G

Greg Maxey

Jonas,

Try this:

Sub DeleteBookmarks()
Dim n As Long
For n = ActiveDocument.Bookmarks.Count To 1 Step -1
ActiveDocument.Bookmarks(n).Delete
Next n

End Sub
 
J

Jonas

Thanks for your reply.

But I dont think this is going to work for me because Im controlling Word
from a non-microsoft language through com-handles.
 
V

Vince

Should be (1).Delete and NOT (n).Delete. I thought it was a typo back then
until Jonathan corrected me.

****************************************
Dim n as Long
For n = 1 to ActiveDocument.Bookmarks.Count
ActiveDocument.Bookmarks(1).Delete
Next n
****************************************
 

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