Jump to content

_WordDocFindReplace issue


ajit
 Share

Recommended Posts

#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

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 by MrMitchell
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...