idbeHoldL

for JOY/ fast pidor help

Sep 30th, 2019
975
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <File.au3>
  2. #include <Array.au3>
  3. #include <Word.au3>
  4. #include <_RecFileListToArray.au3>
  5.  
  6.  
  7. $g_replaceList = IniReadSection('config.ini','words')
  8. ;~  _ArrayDisplay($g_replaceList)
  9.  
  10. $aArray = _RecFileListToArray(@ScriptDir, "*.doc*", 1, 1, 0, 2, "", "")
  11. ;~  _ArrayDisplay($aArray)
  12.  
  13.  
  14. For $i = 1 to UBound($aArray) -1
  15.    ReplaceInWord($aArray[$i])
  16. Next
  17.  
  18.  
  19. Func ReplaceInWord($pathToFile)
  20.  
  21.    ConsoleWrite($pathToFile & @CRLF)
  22.  
  23.    $oAppl = _Word_Create()
  24.    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocOpen Example", _
  25.         "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
  26.  
  27.    $oWordDoc = _Word_DocOpen($oAppl, $pathToFile)
  28.    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFindReplace Example", _
  29.         "Error opening " & $pathToFile  & @CRLF & "@error = " & @error & ", @extended = " & @extended)
  30.  
  31.    ConsoleWrite($oWordDoc & @CRLF)
  32.  
  33.    for $k=1 to UBound($g_replaceList) -1
  34.       $oFind = _Word_DocFindReplace($oWordDoc, $g_replaceList[$k][0], $g_replaceList[$k][1], $WdReplaceAll, 0, False, True)
  35.       If $oFind Then
  36.           ConsoleWrite("Found and replaced." & @CRLF)
  37.       Else
  38.           ConsoleWrite("Not Found" & @CRLF)
  39.       EndIf
  40.  
  41.    Next
  42.    _Word_DocSave($oWordDoc)
  43.    _Word_DocClose($oWordDoc)
  44.    _Word_Quit ($oAppl, 0)
  45.  
  46. EndFunc
RAW Paste Data