Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Delete section breaks at end of word document | Page Layout | |||
In specific document I cannot edit (delete) any text via keyboard | Microsoft Word Help | |||
Add checkboxes with macro in Merge document? | Tables | |||
how do i delete a read-only document | Microsoft Word Help | |||
saved document won't delete | Page Layout |