Finding and Inserting

J

Jen

Hi all. I want to create a macro that will look for words
in the word document that are in [brackets]. Then I want
a prompt to come up that asks for data to be entered to
replace the [brackets]. So for example see the following
sentence . . .

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an [insert
title].

I want a prompt to come up as ask "insert title". When
the user enters the title "Accountant", for example, the
sentence in the document would read

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an Accountant.
 
D

Doug Robbins

The following should do what you want:

Dim tag As Range, question As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[*\]", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set tag = Selection.Range
Set question = Selection.Range.Duplicate
question.End = question.End - 1
question.Start = question.Start + 1
tag.Text = InputBox(question)
Loop
End With

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
G

Guest

That great. Thank you. However, I am so new at this, I
don't even know where to put this code. I have done a
user form in VB and I need to run the form first and then
the macro that will do this. Also, I have several
bracketed items that I will want to search for and
different pop up questions for each bracketed item. Can
you help me do this?
-----Original Message-----
The following should do what you want:

Dim tag As Range, question As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[*\]", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set tag = Selection.Range
Set question = Selection.Range.Duplicate
question.End = question.End - 1
question.Start = question.Start + 1
tag.Text = InputBox(question)
Loop
End With

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Hi all. I want to create a macro that will look for words
in the word document that are in [brackets]. Then I want
a prompt to come up that asks for data to be entered to
replace the [brackets]. So for example see the following
sentence . . .

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an [insert
title].

I want a prompt to come up as ask "insert title". When
the user enters the title "Accountant", for example, the
sentence in the document would read

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an Accountant.


.
 
G

Guest

Oh!! I have figured it out. I love this newsgroup. Thank
you so much for your help. You guys are great!!!!
-----Original Message-----
That great. Thank you. However, I am so new at this, I
don't even know where to put this code. I have done a
user form in VB and I need to run the form first and then
the macro that will do this. Also, I have several
bracketed items that I will want to search for and
different pop up questions for each bracketed item. Can
you help me do this?
-----Original Message-----
The following should do what you want:

Dim tag As Range, question As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="\[*\]", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set tag = Selection.Range
Set question = Selection.Range.Duplicate
question.End = question.End - 1
question.Start = question.Start + 1
tag.Text = InputBox(question)
Loop
End With
be
answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
Hi all. I want to create a macro that will look for words
in the word document that are in [brackets]. Then I want
a prompt to come up that asks for data to be entered to
replace the [brackets]. So for example see the following
sentence . . .

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an [insert
title].

I want a prompt to come up as ask "insert title". When
the user enters the title "Accountant", for example, the
sentence in the document would read

On behalf of Joe's Company, I am pleased to confirm your
acceptance of our offer of employment as an Accountant.


.
.
 

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