I'm really having difficulties working with the COM model for Word. While I understand working with COM and ahk in Excel, I just can't wrap my head around Word. Checking the online documentation for the COM model on Microsoft's site didn't help either.
Could someone please lend me a hand by looking at my code below.
What I want to do is write a macro that would read the Excel file line by line, searching for a specific string and when it finds it, I want to replace it with another string.
Here is my sample code:
Code: Select all
FileSelectFile, Path
oWord := ComObjCreate("Word.Application")
oWord.Visible := True
oWord.Documents.Open(Path)
worddoc := oWord.ActiveDocument.Content.Text
Loop, Parse, worddoc, `r`n
{
Msgbox, %A_Loopfield%
newvar .= A_Loopfield
}
Msgbox, %newvar%
So I understand that I can loop through the file line by line. What I want in this loop is a simple - I want to find every string "10" and replace it with let's say "20"This is a test document
Here are some values – 5, 10, 20, 40
Have fun doing com word ahk
I can do that with StringReplace in AHK, but how would I write that to the file at the correct position? How would I say to word that I want this "10" to become "20"?
Thanks in advance!