15 posts in this topic
Merge word documents
Firstly, thanks for your help in the past.
I have a new activity I need to accomplish.
* need to read a cell in excel (containing a file name)
* open the file name in word (as its a word document
*copy the word document
*paste the word document into the master document
*read next cell in excel
... and repeat until you reach the bottom of the column.
I can read cells open workbooks etc.
But as far as copying and pasting in word - where is the best place to start, and what functions should I be looking at. Or even if autoit is the right system to use?
How to make a newline in Word with COM
Hi all (Especially @water)
I wonder how to do this task in word from autoit.
Assume that i pasted some text into word with this code.
Local $oWord = ObjGet("","Word.Application") Local $wRangeObj = _Word_DocRangeSet($oWord, 0) Local $data = ClipGet() $wRangeObj.Text = $data $wRangeObj.Font.Bold = True So far so good. Now, i need to enter a new line in word and turn the Font.Bold = False.
Currently, i did it with activating the word window and Send() function. But i would like to do it with the help of COM object. How can i do that ?
Cannot save word document - Strange/Unknown error
Hello, I am trying to save an word document but it won't work , This is my REALLY simple script:
#include <Word.au3> Global $oWord = _Word_Create(False, True) _Word_DocSaveAs($oWord) MsgBox(0, @error, @extended) And my MsgBox:
I know that its a COM error because @error is set 2... but what about the COM error code? I cannot find anything related to -2147352570!
word com error trapping possible bug in udf
I am testing intercepting com errors in Word and I have found a possible bug in the UDF, it might not be a bug it just means a workaround.
I have found the com error bug in _Word_Create
Func _Word_Create($bVisible = Default, $bForceNew = Default) Local $oAppl, $bApplCloseOnQuit = False If $bVisible = Default Then $bVisible = True If $bForceNew = Default Then $bForceNew = False If Not $bForceNew Then $oAppl = ObjGet("", "Word.Application") <------- here is the line which causees com error This happens in the following example
#include <Word.au3> main() func main() local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $oWord = _Word_Create() $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Dear.docx", False, Default, True) $myrange = $oDoc.Range $myrange.Select sleep(3000) _Word_DocClose($oDoc) _Word_Quit($oWord) endfunc ; User's COM error function. Will be called if COM error occurs Func _ErrFunc($oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc This script causes a com error to occur and it has the following error
test.au3 (53) : ==> COM Error intercepted ! err.number is: 0x80020006 err.windescription: Unknown name. err.description is: err.source is: err.helpfile is: err.helpcontext is: err.lastdllerror is: 0 err.scriptline is: 53 err.retcode is: 0x00000000 Line 53 is
If Not $bForceNew Then $oAppl = ObjGet("", "Word.Application") as I mentioned above.
When I force a new instance of Word, no error occurs eg
#include <Word.au3> main() func main() local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") $oWord = _Word_Create(True,True) $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\Dear.docx", False, Default, True) $myrange = $oDoc.Range $myrange.Select sleep(3000) _Word_DocClose($oDoc) _Word_Quit($oWord) endfunc So it seems that if I want to open up existing Word instance (use _Word_Create() ) I will have to create my own _Word_Open to bypass this problem.
(If Word is already open the problem will not occur)
I have tried to use _Excel_RangFind, but it fails. It even fails in the example in the help file (see example 1).
This the error
>Running AU3Check (18.104.22.168) from:C:\Program Files (x86)\AutoIt3 input:C:\Program Files (x86)\AutoIt3\Examples\Helpfile\_Excel_RangeFind.au3 +>12:09:10 AU3Check ended.rc:0 >Running:(22.214.171.124):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Program Files (x86)\AutoIt3\Examples\Helpfile\_Excel_RangeFind.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Program Files (x86)\AutoIt3\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex] = $oMatch.Name.Name $aResult[$iIndex] = $oMatch^ ERROR My own code fails with a similar message
Local $aResult = _Excel_RangeFind($oWorkbook, "john") _ArrayDisplay($aResult) Help please.