How to find and replace a text in MS Word document and then save it as a new document?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to find and replace a text in MS Word document and then save it as a new document?

14 Jan 2018, 10:14

Hello friends..

i want to find specific text in a OldDoc.docx and replace it with another text and then save it as Newdoc.docx at another location
My codes are-

Code: Select all

f1::
Gui, Add, Edit, x252 y20 w100 h30 vdate,
Gui, Add, Text, x142 y20 w100 h30 , Date
gui, add, button, x142 y230 w100 h30, ok
Gui, Show, w479 h379, Untitled GUI
return
buttonOk:
gui, submit
ow:= ComObjCreate("word.application")
ow1:= ow.documents.Open("D:\14.1.18\words\OldDoc.docx")
st:= "14.01.2018"
ow1.selection.find.execute(st,0,0,0,0,0,1,1,0,date,2)
ow1.saveas("C:\Users\htc\Desktop\NewDoc.docx")
return
When i run these codes, it opens a small gui with one edit Box and ok button. I fill date in Edit box and then press Ok button then it shows a msgbox saying- OldDoc.docx is locked by htc. however i have not locked OldDoc.docxThen it shows one more error msgbox- one is unknown name... specifically: selection
however it creates NewDoc.docx at C:\Users\htc\Desktop\NewDoc.docx but it does not replace the date in it.

please tell me the solution of the problem...
thanks a lot..
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, jaka1, Spawnova and 278 guests