Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing a line of Text in word

Status
Not open for further replies.
May 18, 2006
3
CA
Hi,

I'm not very experienced with VBA.

I'm using VBA in a word document to setup some stuff. I'm not having an problems except that I need to clear a line of text.

Specifically, I want to clear a line starting at a specific Bookmark until the end of that line. By clear I mean remove all the text on that line but not remove the line itself if that makes sense.

Thanks,

Skoo
 
Sorry;

Also, I do not want to delete the bookmark as I will be using it again later.

If anyone knows how to do this I'd be grateful if you'd share!
 
Does the "line" end with a paragraph mark...or does the text wrap into the next line? In other words, if you COULD delete to the end of the "line", would more text now back up, and there would still be text on that line?

Also:

1. is this part of some other running code?
2. why are you doing this? why is it needed?

Essentially though, you can make a Range of the line starting from the END of your bookmark, to the end of the line....then delete it. Like this:
Code:
Sub DeleteFromBookmark()
Dim r As Word.Range
[COLOR=red]' go to a bookmark   I am using "Here"[/color red]
Selection.GoTo what:=wdGoToBookmark, Name:="Here"
Set r = ActiveDocument.Range(Start:=Selection.Range.End, _
    End:=ActiveDocument.Bookmarks("\line").Range.End)
r.Delete
Set r = Nothing
End Sub

NOTE: I am using the Selection to be able to use the Line pre-defined bookmark. So the Selection must be moved to the line the bookmark is on. If the Selection is already on that line - which is why i asked about other code running - then you could use (which the same bookmark "Here":
Code:
Set r = ActiveDocument.Range(Start:=ActiveDocument.Bookmarks("Here").Range.End, _
 End:=ActiveDocument.Bookmarks("\line").Range.End)

Gerry
 
I have a form popup when the doc is opened where the user must select one of our branch locations from a combo and depending on which location is selected the address fields will be filled out.

I want to clear the fields before the new text is added incase the user leaves data there from previous sessions.

Also, is it necessary to select from the END of the bookmark? Why not the beginning?
 
Number 1:[quote}I want to clear the fields before the new text is added incase the user leaves data there from previous sessions.[/quote]Then DON'T. Why would you????? Proper design would never do that - unless of course you want it to. Are you using a template (.DOT)?

Number 2:
Also, is it necessary to select from the END of the bookmark? Why not the beginning?
Hmmmmm, just doing what you asked for...
Also, I do not want to delete the bookmark as I will be using it again later.
If you deleted from the beginning, it takes the bookmark.

Although....it depends on whether you are handling the bookmark range text properly. That is, if the bookmark range INCLUDES the text, or not.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top