gilbro
07-15-2015, 08:10 AM
I have text in a Word file that looks something like this:
A. Hello, I Love Lucy, Dodge.
[Some other text]
B. Hello, The Bachelor, Chevy.
[Some other text]
C. Hello, The Tonight Show, Toyota.
[Some other text]
D. Hello, Seinfeld, Toyota.
[Some other text]
What I want is a script to convert it to:
A. Hello, I Love Lucy, Dodge.
[Some other text]
B. Hello, The Bachelor, Chevy.
[Some other text]
C. The Tonight Show, Toyota.
[Some other text]
D. Seinfeld, Toyota.
[Some other text]
Specifically, every time I find that the last word in the line is "Toyota" (and not some other car), then go to the beginning of the line and keep the listing letter but delete "Hello, ".
I have tried the following:
Selection.Find.ClearFormatting
With Selection.Find
.Text = ". Hello,?*, Toyota."
.Forward = True
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=7, Extend:=wdExtend
Selection.TypeBackspace
...but this selects everything after the "A." all the way through the end of line C. It will work for the first instance (in line C), but if I run it a second time, it will again find everything from after the "A." to the end of line C, then go back to the beginning of line C and delete the first 7 characters of "The Tonight Show."
I haven't been clever enough to find the right search string that finds only the whole line which begins "X. Hello," and ends with ", Toyota", and which doesn't also include parts of preceding lines.
Help will be appreciated.
Thanks, Gil
A. Hello, I Love Lucy, Dodge.
[Some other text]
B. Hello, The Bachelor, Chevy.
[Some other text]
C. Hello, The Tonight Show, Toyota.
[Some other text]
D. Hello, Seinfeld, Toyota.
[Some other text]
What I want is a script to convert it to:
A. Hello, I Love Lucy, Dodge.
[Some other text]
B. Hello, The Bachelor, Chevy.
[Some other text]
C. The Tonight Show, Toyota.
[Some other text]
D. Seinfeld, Toyota.
[Some other text]
Specifically, every time I find that the last word in the line is "Toyota" (and not some other car), then go to the beginning of the line and keep the listing letter but delete "Hello, ".
I have tried the following:
Selection.Find.ClearFormatting
With Selection.Find
.Text = ". Hello,?*, Toyota."
.Forward = True
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=7, Extend:=wdExtend
Selection.TypeBackspace
...but this selects everything after the "A." all the way through the end of line C. It will work for the first instance (in line C), but if I run it a second time, it will again find everything from after the "A." to the end of line C, then go back to the beginning of line C and delete the first 7 characters of "The Tonight Show."
I haven't been clever enough to find the right search string that finds only the whole line which begins "X. Hello," and ends with ", Toyota", and which doesn't also include parts of preceding lines.
Help will be appreciated.
Thanks, Gil