Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-09-2011, 08:28 AM
hklein hklein is offline delete all bookmark text Windows XP delete all bookmark text Office 2007
Novice
delete all bookmark text
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default 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"
How to work with the bookmark-collection?

Thank you
Reply With Quote
  #2  
Old 08-09-2011, 04:22 PM
gmaxey gmaxey is offline delete all bookmark text Windows XP delete all bookmark text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-09-2011, 11:59 PM
hklein hklein is offline delete all bookmark text Windows XP delete all bookmark text Office 2007
Novice
delete all bookmark text
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 08-10-2011, 04:13 AM
gmaxey gmaxey is offline delete all bookmark text Windows XP delete all bookmark text Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 08-10-2011, 04:33 AM
hklein hklein is offline delete all bookmark text Windows XP delete all bookmark text Office 2007
Novice
delete all bookmark text
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default

Thank you, your help is appreciated very much anyway.
Have a nice day
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
delete all bookmark text 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:00 AM.


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