A typo was discovered in a word document that we receive. Was advised that they are not going to provide a corrected version to users until there is a major change to the file. Since via Access, I have been able to edit text elsewhere in the word doc, I thought would be simple enough to add a bit more code to my existing function to handle fixing the typo. I was able to locate the text and can view it in the immediate window, so I know it is finding the header data. I first tried
This didn't correct the typo, instead it obliterated the formatting, removed graphics and changed colour of text from Black to Blue.
I then tried the version further below and it tells me (via stepping through and using ? in the immediate window) that nothing is found.
I can isolate the text in question in the immediate window as such:
--NOTE, I changed the wording of the above since didn't want to display
actual text, so the mid function numbers will be off.--
What might I be missing? Thanks.
Code:
worddoc.sections(1).headers(2).Range.Text=Replace(worddoc.sections(1).headers(2).Range.Text, "Elecricfication", "Electrification")
This didn't correct the typo, instead it obliterated the formatting, removed graphics and changed colour of text from Black to Blue.
I then tried the version further below and it tells me (via stepping through and using ? in the immediate window) that nothing is found.
Code:
? worddoc.sections(1).headers(2).range.text
/
THIS IS FOR
EXAMPLE Purposes
Electricfication Data Services
Contract No.: 58-CTR-Q-091
/
I can isolate the text in question in the immediate window as such:
--NOTE, I changed the wording of the above since didn't want to display
actual text, so the mid function numbers will be off.--
Code:
? mid(worddoc.sections(1).headers(2).Range.Text,46,18)
Electricfication
Code:
With WordApp
With WordDoc.sections(1).headers(2).Range.Find
.Text = "Elecricfication"
.Replacement.Text = "Electrification"
.MatchWholeWord = True
'Replaces all occurences
'.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindStop
'Replaces one occurence
'.Execute Replace:=wdReplaceOne, Forward:=True, Wrap:=wdFindStop
.Execute Replace:=1, Forward:=True, Wrap:=0
End With
End With
What might I be missing? Thanks.