ajit Posted August 12, 2011 Share Posted August 12, 2011 #include <Word.au3> $oWordApp = _WordCreate (@ScriptDir & "\Test.doc") $oDoc = _WordDocGetCollection($oWordApp, 0) $oDoc.Range.insertAfter("this" & @CR) FileDelete("a.txt") $file = FileOpen("a.txt", 1) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $i = 1 to 10 ; IF THIS NUMBER IS CHANGED FROM 10 TO 100 _WordDocFindReplace DOES NOT WORK FileWrite($file, "Line " & $i) Next FileClose($file) FileOpen("a.txt") $String_to_replace = Fileread($file) $oFind = _WordDocFindReplace($oDoc, "this", $String_to_replace) Hi, Please see attached script wherein I create a text file and then use Readfile to get text from that file to use in _WordDocFindReplace but as soon as I increase the number of characters in text file _WordDocFindReplace will not work. Can someone guide me on this? Regards Ajit Link to comment Share on other sites More sharing options...
ajit Posted August 17, 2011 Author Share Posted August 17, 2011 Any work around possible? Link to comment Share on other sites More sharing options...
MrMitchell Posted August 17, 2011 Share Posted August 17, 2011 (edited) Any work around possible? Yes. From your For loop: For $i = 1 to 100 ; IF THIS NUMBER IS CHANGED FROM 10 TO 100 _WordDocFindReplace DOES NOT WORK FileWrite($file, "Line " & $i) Next FileClose($file) FileOpen("a.txt") $String_to_replace = Fileread($file) ClipPut($String_to_replace) ;Put it on the clipboard $oFind = _WordDocFindReplace($oDoc, "this", "^c") ;Per MSDN documentation use this ^c to paste from the clipboard. Reference: http://msdn.microsoft.com/en-us/library/....word.find.execute%28v=office. Scroll down to ReplaceWith to see where I got this from. They stated this is how you would use it for a picture but it seems to work fine with text too. To answer your original question, I have no idea if there's a limit to the number of characters, couldn't figure that out. But at least you have a workaround. Edited August 17, 2011 by MrMitchell KEHT 1 Link to comment Share on other sites More sharing options...
ajit Posted August 17, 2011 Author Share Posted August 17, 2011 @MrMitchell, That was a pleasent surprise. Worked flawlessly. Thanks very much for your effort in helping me out. Regards, Ajit Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now