#1
|
|||
|
|||
Delete Range After Bookmark?
Hey guys,
quick question: I've written an VBA Code to get some input from Excel into a Word File. I used to following code: wdDoc.Bookmarks("Note").Range.InsertAfter Range("Note") So, that works out fine. But at the second time of opening the Word file, the input is written down for a second time (OFC). I couldn't find a code to delete the last input after the bookmark... is that possible? Regards, Elfe |
#2
|
|||
|
|||
"On opening"...so the code is in Document_Open?
|
#3
|
|||
|
|||
No.. to be specific, the VBA is in Excel.. I'm trying to give students some kind of a certificate, giving them an overview of their grades (originally from access - viewable in Excel- printable in Word)
|
#4
|
||||
|
||||
The proper way to update bookmark content is to add the content to the bookmark, not after it. Use code like:
Code:
Sub UpdateBookmark (wdDoc as Document, BmkNm as string, NewTxt as string) Dim BmkRng as Word.Range With wdDoc If.Bookmarks.Exists(BmkNm) Then Set BmkRng =.Bookmarks(BmkNm).Range BmkRng.Text = NewTxt .Bookmarks.Add BmkNm, BmkRng End if End With Set BmkRng = Nothing End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word VBA: Cannot Edit Range (Delete characters except the first in a table cell) | tinfanide | Word VBA | 3 | 04-27-2012 09:48 AM |
delete all bookmark text | hklein | Word VBA | 4 | 08-10-2011 04:33 AM |
Can't delete range - error 5904 | expatriate | Word VBA | 1 | 06-03-2011 12:12 AM |
Newbie: Delete Bookmark | expatriate | Word VBA | 4 | 06-02-2011 01:12 AM |
delete email message via blackberry and have it delete on my pop3 and my outlook | Iamthestorm | Outlook | 2 | 10-28-2010 12:21 AM |