Reply
 
Thread Tools Display Modes
  #1   Report Post  
Deane-Denver
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

I need to Delete All Bookmarks at once in a word document - it is not a
template
  #2   Report Post  
Doug Robbins - Word MVP
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

If you want to delete the bookmarks, but retain anything that they contain,
use:

Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Delete
Next i
End With

If you want to delete the bookmarks and their contents, then use:

Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Deane-Denver" wrote in message
...
I need to Delete All Bookmarks at once in a word document - it is not a
template



  #3   Report Post  
macropod
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Of course, you might also want to preserve whatever was referring to the
bookmarks before deleting them ...

Cheers


"Doug Robbins - Word MVP" wrote in message
...
If you want to delete the bookmarks, but retain anything that they

contain,
use:

Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Delete
Next i
End With

If you want to delete the bookmarks and their contents, then use:

Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Deane-Denver" wrote in message
...
I need to Delete All Bookmarks at once in a word document - it is not a
template





  #4   Report Post  
Greg
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Doug,

Run the code you posted with a couple of placeholder bookmarks and you
will see undesirable results. The character immediately to the right
of the bookmark is deleted but the bookmark stays put ;-(

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

Now consider this:
Sub DeleteAllBookmarksRefined()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
If Len(.Bookmarks(i).Range) 0 Then
.Bookmarks(i).Range.Delete
Else
.Bookmarks(i).Delete
End If
Next i
End With
End Sub

Cheers.

  #5   Report Post  
Doug Robbins - Word MVP
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Hi Greg,

Your version of "placeholder bookmarks" do not have content and the second
macro was for use if you wanted to delete both the bookmarks AND their
contents.

While as far as I can tell, there is no term in Word that equates to a
"placeholder bookmark", my version of it would always include a single space
so that if I used .InsertBefore on the .Range of the bookmark, the text
would be inserted inside the bookmark and could thus be cross-referenced.
--
Regards,

Doug Robbins - Word MVP

"Greg" wrote in message
oups.com...
Doug,

Run the code you posted with a couple of placeholder bookmarks and you
will see undesirable results. The character immediately to the right
of the bookmark is deleted but the bookmark stays put ;-(

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

Now consider this:
Sub DeleteAllBookmarksRefined()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
If Len(.Bookmarks(i).Range) 0 Then
.Bookmarks(i).Range.Delete
Else
.Bookmarks(i).Delete
End If
Next i
End With
End Sub

Cheers.





  #6   Report Post  
Greg Maxey
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Doug,

I got the term "Placeholder bookmark" he
http://word.mvps.org/FAQs/MacrosVBA/...hBookmarks.htm

(1) Placeholder Bookmarks
If you click somewhere in the document and insert a bookmark it will look
like a beam I – this is a “placeholder” bookmark.

If a document has one of those kind and you run this code:

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

It will delete the character following the bookmark and leave the bookmark
intact (i.e, it doesn't delete the bookmark). I am not trying to justify
what is or is not the correct way to use bookmarks, merely pointing out that
running the above code in a document that does contain a "placeholder
bookmark" will have undesirable results. ;-)


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Doug Robbins - Word MVP wrote:
Hi Greg,

Your version of "placeholder bookmarks" do not have content and the
second macro was for use if you wanted to delete both the bookmarks
AND their contents.

While as far as I can tell, there is no term in Word that equates to a
"placeholder bookmark", my version of it would always include a
single space so that if I used .InsertBefore on the .Range of the
bookmark, the text would be inserted inside the bookmark and could
thus be cross-referenced.
"Greg" wrote in message
oups.com...
Doug,

Run the code you posted with a couple of placeholder bookmarks and
you will see undesirable results. The character immediately to the
right of the bookmark is deleted but the bookmark stays put ;-(

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

Now consider this:
Sub DeleteAllBookmarksRefined()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
If Len(.Bookmarks(i).Range) 0 Then
.Bookmarks(i).Range.Delete
Else
.Bookmarks(i).Delete
End If
Next i
End With
End Sub

Cheers.



  #7   Report Post  
Doug Robbins - Word MVP
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Hi Greg,

That makes it an Ibby term. I searched for it in the Word Help file and did
not come up with it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Greg Maxey" wrote in message
...
Doug,

I got the term "Placeholder bookmark" he
http://word.mvps.org/FAQs/MacrosVBA/...hBookmarks.htm

(1) Placeholder Bookmarks
If you click somewhere in the document and insert a bookmark it will look
like a beam I - this is a "placeholder" bookmark.

If a document has one of those kind and you run this code:

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

It will delete the character following the bookmark and leave the bookmark
intact (i.e, it doesn't delete the bookmark). I am not trying to justify
what is or is not the correct way to use bookmarks, merely pointing out
that running the above code in a document that does contain a "placeholder
bookmark" will have undesirable results. ;-)


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Doug Robbins - Word MVP wrote:
Hi Greg,

Your version of "placeholder bookmarks" do not have content and the
second macro was for use if you wanted to delete both the bookmarks
AND their contents.

While as far as I can tell, there is no term in Word that equates to a
"placeholder bookmark", my version of it would always include a
single space so that if I used .InsertBefore on the .Range of the
bookmark, the text would be inserted inside the bookmark and could
thus be cross-referenced.
"Greg" wrote in message
oups.com...
Doug,

Run the code you posted with a couple of placeholder bookmarks and
you will see undesirable results. The character immediately to the
right of the bookmark is deleted but the bookmark stays put ;-(

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

Now consider this:
Sub DeleteAllBookmarksRefined()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
If Len(.Bookmarks(i).Range) 0 Then
.Bookmarks(i).Range.Delete
Else
.Bookmarks(i).Delete
End If
Next i
End With
End Sub

Cheers.





  #8   Report Post  
Greg Maxey
 
Posts: n/a
Default I need to Delete All Bookmarks at once in a document

Hi Doug,

Ok, forget Ibby. Do you concede that it is humanly possible for a person,
not yourself of course, to create a document that has a dispersion of
bookmarks some enclosing text and some with a zero length range and that
these bookmarks of the second type have at least, by a small segment of the
population, been referred to as "placeholder bookmarks?"

This person then makes the following request:

I need to Delete All Bookmarks at once in a word document - it is not a
template
A very knowledgeable person replies.

If you want to delete the bookmarks and their contents, then use:


Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With

The person ponders and decides yes I do want to delete the bookmarks and
their contents. He or she executes the code and thousands of bookmarks
vanish in the blink of an eye. FileSave quit Word and off to catch the
morning train.

Can you imagine the dismay when that person realizes later that many of the
bookmarks, the placeholder type, are still present and not only that but a
single adjacent character has been deleted instead?

Cheers




--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Doug Robbins - Word MVP" wrote in message
...
Hi Greg,

That makes it an Ibby term. I searched for it in the Word Help file and
did not come up with it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Greg Maxey" wrote in message
...
Doug,

I got the term "Placeholder bookmark" he
http://word.mvps.org/FAQs/MacrosVBA/...hBookmarks.htm

(1) Placeholder Bookmarks
If you click somewhere in the document and insert a bookmark it will look
like a beam I - this is a "placeholder" bookmark.

If a document has one of those kind and you run this code:

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

It will delete the character following the bookmark and leave the
bookmark intact (i.e, it doesn't delete the bookmark). I am not trying
to justify what is or is not the correct way to use bookmarks, merely
pointing out that running the above code in a document that does contain
a "placeholder bookmark" will have undesirable results. ;-)


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Doug Robbins - Word MVP wrote:
Hi Greg,

Your version of "placeholder bookmarks" do not have content and the
second macro was for use if you wanted to delete both the bookmarks
AND their contents.

While as far as I can tell, there is no term in Word that equates to a
"placeholder bookmark", my version of it would always include a
single space so that if I used .InsertBefore on the .Range of the
bookmark, the text would be inserted inside the bookmark and could
thus be cross-referenced.
"Greg" wrote in message
oups.com...
Doug,

Run the code you posted with a couple of placeholder bookmarks and
you will see undesirable results. The character immediately to the
right of the bookmark is deleted but the bookmark stays put ;-(

Sub Test()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
.Bookmarks(i).Range.Delete
Next i
End With
End Sub

Now consider this:
Sub DeleteAllBookmarksRefined()
Dim i As Long
With ActiveDocument
For i = .Bookmarks.Count To 1 Step -1
If Len(.Bookmarks(i).Range) 0 Then
.Bookmarks(i).Range.Delete
Else
.Bookmarks(i).Delete
End If
Next i
End With
End Sub

Cheers.







Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete section breaks at end of word document Chris O. Page Layout 7 October 4th 06 09:24 AM
In specific document I cannot edit (delete) any text via keyboard Roberto Cabestany Microsoft Word Help 1 October 20th 05 04:57 PM
Add checkboxes with macro in Merge document? Bryan L Tables 3 October 19th 05 04:05 PM
how do i delete a read-only document bellabell Microsoft Word Help 3 June 16th 05 08:01 AM
saved document won't delete happy2day Page Layout 4 May 11th 05 06:17 AM


All times are GMT +1. The time now is 01:21 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"