If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#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. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Why can't I delete text in a document (not read-only) | PensCrazy | General Discussion | 3 | November 15th, 2005 08:48 PM |
macros and SharePoint WSS document libraries | [email protected] | New Users | 0 | October 6th, 2005 03:42 AM |
Bookmarks appearing in HTML Format document links | AndyBear | General Discussion | 3 | June 1st, 2005 02:45 PM |
Delete a watermark from a Word document converted from Wordperfec. | britcarfan | General Discussion | 1 | October 22nd, 2004 08:41 PM |
Need to delete the last page of my document which contains header. | GAS | General Discussion | 1 | October 19th, 2004 06:39 PM |