#1
|
|||
|
|||
delete all bookmark text
Hello,
can anybody help me ? I would like to delete all the values located after a bookmark in the document, inserted like this Code:
docWord.bookmarks("name").Range.Text="anything" Thank you |
#2
|
|||
|
|||
I think you are going to have to do that manually. Here is why. When you insert text like your example you are insert the text "at" the bookmark. Specifically just after it. Once it is there, there is nothing to define what the "end" range is.
The better way that would give you a mean to later to delete the text is to insert text "in" a bookmark. Sub ScratchMacro() Dim oRng As Word.Range Set oRng = ActiveDocument.Bookmarks("Name2").Range oRng.Text = "anything" ActiveDocument.Bookmarks.Add "Name2", oRng End Sub You can then delete the text or the text and the bookmark with: Sub ScratchMacroII() 'A quick macro scratch pad created by Greg Maxey Dim i As Long Dim pStr As String Dim oRng As Word.Range 'Delete text and preserve bookmark For i = ActiveDocument.Bookmarks.Count To 1 Step -1 Set oRng = ActiveDocument.Bookmarks(i).Range pStr = ActiveDocument.Bookmarks(i).Name oRng.Text = "" ActiveDocument.Bookmarks.Add pStr, oRng Next i 'delete both For i = ActiveDocument.Bookmarks.Count To 1 Step -1 ActiveDocument.Bookmarks(i).Range.Delete Next i End Sub |
#3
|
|||
|
|||
Hello,
thanks, in fact, in the meantime I have already realized the logical bug in my thinking. I can see, that you are an expert, so let me describe the task I have to do a little bit more specific. I am making an excel macro, and want to put text from excel into word. That wouldn'be a problem, but the word file should be embedded at excel. The embedded file is a template, and I have to insert text into pre-defined place. That's why I am using bookmarks. The problem is, that if I put anyithing to this document, then I it is saved immediately, so on the next use I have to delete the old values first. That's why I wanted to use the bookmark collection. Do you can maybe a more professional methods. Thank you very much the codes so far. |
#4
|
|||
|
|||
I'm sorry but I am not very famiiliar with Excel or the process you are trying to do so I don't know how I could help further.
|
#5
|
|||
|
|||
Thank you, your help is appreciated very much anyway.
Have a nice day |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Newbie: Delete Bookmark | expatriate | Word VBA | 4 | 06-02-2011 01:12 AM |
Delete text | Michael007 | Office | 13 | 01-01-2011 10:38 PM |
delete email message via blackberry and have it delete on my pop3 and my outlook | Iamthestorm | Outlook | 2 | 10-28-2010 12:21 AM |
Highlighted text won't delete - when I press enter | Gague | Word | 2 | 07-09-2010 12:53 PM |
Need to delete style and style text | mclan | Word | 0 | 08-04-2008 12:05 PM |