Inserting at a bookmark if text found

R

Roger Marrs

I'm trying to search for various strings of text in a document and if a
string is found, then inserting a block of text that's triggered by that
string into a different place in the document.

I understand how to code for the searches, and how to set up the default
text that will be added using Dim as String variables. What I'm having
trouble understanding is how to write the code that says "I've found the
string of text, now I'm going to insert the Variable1 string at Bookmark1"

Hopefully the way I've explained what I'm trying to accomplish makes sense.

Roger Marrs
 
J

Jay Freedman

I'm trying to search for various strings of text in a document and if a
string is found, then inserting a block of text that's triggered by that
string into a different place in the document.

I understand how to code for the searches, and how to set up the default
text that will be added using Dim as String variables. What I'm having
trouble understanding is how to write the code that says "I've found the
string of text, now I'm going to insert the Variable1 string at Bookmark1"

Hopefully the way I've explained what I'm trying to accomplish makes sense.

Roger Marrs

Hi Roger,

After you set up the Find object, do something like this:

If .Execute Then
ActiveDocument.Bookmarks("Bookmark1").Range.Text = Variable1
End If

This simple version clobbers the bookmark as it inserts the text. If
you need to have the bookmark still present after the insert, see
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
R

Roger Marrs

That worked great. Thank you.
Jay Freedman said:
Hi Roger,

After you set up the Find object, do something like this:

If .Execute Then
ActiveDocument.Bookmarks("Bookmark1").Range.Text = Variable1
End If

This simple version clobbers the bookmark as it inserts the text. If
you need to have the bookmark still present after the insert, see
http://www.word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top