jagrenet
Board Regular
- Joined
- Feb 23, 2022
- Messages
- 81
- Office Version
- 365
- 2013
- 2011
- 2010
- Platform
- Windows
Hello Gurus,
I am using VBA within Excel to manipulate a Word Document.
So far everything I have written is working very well but, I have now hit a brick wall. I have a sentence in which I am replacing some text in a specific area which, is simple enough. Find the text, set the Insertion Point, .... replace the text. However, .... the text I intend to replace is largely dynamic and never consistent. It could be one word, three words, eight words.
At this point I have used -
Selection
.StartIsActive = False
.Extend Character:="f" ....... which works pretty well, until I get a word with 2 "f"s on the end of it such as Sheriff.
An example sentence would be something like;
"I am compiling and sending this report to the Something County Sheriff for their review". The "Something County Sheriff" is the dynamic range that I need to select and replace.
Using the code above, the selection is "trying" to get to the "f" in the word "for" but, stops at the first "f" in Sheriff.
If the sentence read - "I am compiling and sending this report to the Local State Police for their review", this code would work as it is intended. What I am searching for is a way to use "the" as my Start point and "for" as my End point but again, ...... being dynamic in the Agency's name, the "Start/End" method will ultimately be unreliable.
I have studied the Start/End Method which uses (Unit:=wdCharacter, Count:=x) however, I have no way of determining "x" at Runtime, due to the dynamic nature.
I have also considered using an Array but again, that won't work either because I don't know exactly where the Selection is going to end every time.
Any suggestions ??
Thanks in advance,
Jeff
I am using VBA within Excel to manipulate a Word Document.
So far everything I have written is working very well but, I have now hit a brick wall. I have a sentence in which I am replacing some text in a specific area which, is simple enough. Find the text, set the Insertion Point, .... replace the text. However, .... the text I intend to replace is largely dynamic and never consistent. It could be one word, three words, eight words.
At this point I have used -
Selection
.StartIsActive = False
.Extend Character:="f" ....... which works pretty well, until I get a word with 2 "f"s on the end of it such as Sheriff.
An example sentence would be something like;
"I am compiling and sending this report to the Something County Sheriff for their review". The "Something County Sheriff" is the dynamic range that I need to select and replace.
Using the code above, the selection is "trying" to get to the "f" in the word "for" but, stops at the first "f" in Sheriff.
If the sentence read - "I am compiling and sending this report to the Local State Police for their review", this code would work as it is intended. What I am searching for is a way to use "the" as my Start point and "for" as my End point but again, ...... being dynamic in the Agency's name, the "Start/End" method will ultimately be unreliable.
I have studied the Start/End Method which uses (Unit:=wdCharacter, Count:=x) however, I have no way of determining "x" at Runtime, due to the dynamic nature.
I have also considered using an Array but again, that won't work either because I don't know exactly where the Selection is going to end every time.
Any suggestions ??
Thanks in advance,
Jeff