Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2013, 11:12 AM
VBA_Elfe VBA_Elfe is offline Delete Range After Bookmark? Windows 7 64bit Delete Range After Bookmark? Office 2010 64bit
Novice
Delete Range After Bookmark?
 
Join Date: Apr 2013
Posts: 2
VBA_Elfe is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 04-04-2013, 12:44 PM
fumei fumei is offline Delete Range After Bookmark? Windows 7 64bit Delete Range After Bookmark? Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

"On opening"...so the code is in Document_Open?
Reply With Quote
  #3  
Old 04-05-2013, 01:53 AM
VBA_Elfe VBA_Elfe is offline Delete Range After Bookmark? Windows 7 64bit Delete Range After Bookmark? Office 2010 64bit
Novice
Delete Range After Bookmark?
 
Join Date: Apr 2013
Posts: 2
VBA_Elfe is on a distinguished road
Default

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)
Reply With Quote
  #4  
Old 04-05-2013, 05:05 AM
macropod's Avatar
macropod macropod is offline Delete Range After Bookmark? Windows 7 64bit Delete Range After Bookmark? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Range After Bookmark? 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 Range After Bookmark? 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
Delete Range After Bookmark? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft