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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete text

Status
Not open for further replies.

eagleclaw

Programmer
Sep 20, 2002
19
US
I am trying to delete the text that has been inserted into a bookmark programatically.
I tried
With wordapp
.ActiveDocument.Bookmarks("FundContact").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("Official_Name").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("OffName").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("Fund_Address").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("Fund_City").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("Fund_State").Select
.Selection.Text = " "
.ActiveDocument.Bookmarks("Fund_Zip").Select
.Selection.Text = " "
End With

but that does not remove the inserted text
 
Hi eagleclaw,

If the text was inserted into the bookmark then your code should work. If it was inserted at (i.e. after) the bookmark then the bookmark will not actually include the text - it will just represent the start point and you need to be able to identify the end of the text as well in order to delete it. Can you post the code which does the insertion.

Enjoy,
Tony
 
Here is my insertion code
With wordapp
.Visible = True
.Documents.Open (strDocPath)
.ActiveDocument.Bookmarks("FundContact").Select
.Selection.Text = rst![Client Contact]
.ActiveDocument.Bookmarks("Official_Name").Select
.Selection.Text = rst![Official Name]
.ActiveDocument.Bookmarks("OffName").Select
.Selection.Text = rst![Official Name]
.ActiveDocument.Bookmarks("Fund_Address").Select
.Selection.Text = rst![Fund_City]
.ActiveDocument.Bookmarks("Fund_State").Select
.Selection.Text = rst![Fund_State]
.ActiveDocument.Bookmarks("Fund_Zip").Select
.Selection.Text = rst![Fund_Zip]
End With

basically the same
 
Hi eagleclaw,

A bookmark may be a point or a block of text in a document.

If it is a point then your code will insert text after it in both your insert and your delete code.

If it is a block of text your insert will replace it and your delete will give an erro because it isn't there any more.

As you don't mention any errors, I assume what you have is the first case and your delete becomes a problem.

Depending on what else you do with the bookmarks you might consider re-assigning them to include the inserted text:

A sample insert:

Code:
        .ActiveDocument.Bookmarks("FundContact").Select
        .Selection.Text = rst![Client Contact]
        .ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="FundContact"

And a sample delete:

Code:
        .ActiveDocument.Bookmarks("FundContact").Select
        .Selection.Delete
        .ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="FundContact"

Enjoy,
Tony
 
Now I keep getting the dreaded "Object Required" error at this line

.ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="FundContact"
 
Another variable that I haven't mentioned is that I am doing this from access.
 
Very quickly because I'm about to go out. Try putting a dot in front of Selection.Range. Shouldn't make any difference frm Access but I will try it tonight when I return if you still ahve the problem.

Tony
 
Putting the dot in front of selection solved the problem, thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top