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

How 2 embed selection into text that includes itself?!

Status
Not open for further replies.

fai013

Technical User
Jan 15, 2011
1
CA
Hi All,

I'm trying to wrap my head around how to do the following in MS Word 2000. Below is a sample of the document before the macro. Its like a simple multiple choice questionnaire.


Q3a. How many umbrellas do you have?

6 umbrellas
7 umbrellas
8 umbrellas
9 umbrellas or more

Q3b. What are the colours of your umbrellas?

red
blue
green
multicolored

S4. Which direction do you think umbrella fashion is going?

w surreal
x classic
y modern
z minimal


I plan to select each of the three questions, and then change them one at a time using a macro. The multiple choice responses below the question will remain untouched.

*LL Q3a L=2 M=1 N=1
[Q3a. How many umbrellas do you have?]
*SL Q3a

1 umbrella
2 umbrellas
3 umbrellas
4 umbrellas or more


*LL Q3b L=2 M=1 N=1
[Q3b. What are the colours of your umbrellas?]
*SL Q3b

1 red
2 blue
3 green
4 multicolored



*LL S4 L=2 M=1 N=1
[S4. Which direction do you think umbrella fashion is going?]
*SL S4

1 surreal
2 classic
3 modern
4 minimal


I know that I can find the Q3a (without the period at the end) with the following code:

With Selection.Find
'Clear the formatting
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
'Find word begining with a letter Q then any # of characters then
' ending with a lower case letter
.Text = "<[Q]*[a-z]"

But then I can't use this "find" for question S4 since it doesn't start with a Q. Can anyone help me with this problem. If I can solve this problem, I can use the solution to solve all of my other issues, which all seem to revolve around finding things in a selection, and then using those found things in some type of mixture of of other codes.
 
Hi fai013,

To find any word beginning with Q or S, you could use:
.Text = "<[QS]{1}*>"

However, it appears that what you might really need is to find a Q or S followed by a number, then possibly some more characters:
.Text = "<[QS]{1}[0-9]{1,}*>"

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top