Xenio Posted May 9, 2019 Posted May 9, 2019 Hi Guys, I have attached an image of the error codes I am getting when trying to use _Word_DocOpen My path is correct. This is my code: expandcollapse popup#include <Word.au3> #include <Excel.au3> #include <MsgBoxConstants.au3> ;Room Number + Serial Path $excel = @ScriptDir & "\RoomSerials.xlsx" ;Template Document Path Global $template = @ScriptDir & "\FCUITP.docx" $initXls = _Excel_Open(False, False, False, True, False) If @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ITP Maker", "Error creating a new Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Exit EndIf $oWord = _Word_Create() If @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ITP Maker", "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Exit EndIf $oDoc = _Word_DocOpen($oWord, $template) If @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ITP Maker", "Error opening Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Exit EndIf $xlsbook = _Excel_BookOpen($initXls, $excel, False, False) If @error <> 0 Then MsgBox($MB_SYSTEMMODAL, "ITP Maker", "Error opening excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Exit EndIf $sheetList= _Excel_SheetList($xlsbook) $rmi = 2 $rmnumberprev = "$room$" $rmserialprev = "$wcserial$" While $rmi < 70 $rmnumber = _Excel_RangeRead($xlsbook, $sheetList[0][0], "A"&$rmi) $rmserial = _Excel_RangeRead($xlsbook, $sheetList[0][0], "B"&$rmi) $s = _Word_DocFindReplace($oDoc,$rmnumberprev,$rmnumber) msgbox(0,"",$s & " | " & @error) _Word_DocFindReplace($oDoc,$rmserialprev,$rmserial) _Word_DocExport($oDoc,@ScriptDir & "\Sheets\ITP_Room_"&$rmnumber&".pdf") $rmnumberprev = $rmnumber $rmserialprev = $rmserial $rmi = $rmi + 1 WEnd _Excel_Close($initXls,False,True) _Word_DocClose($oDoc) Exit I also get the SAME error when using the _Word_DocOpen EXAMPLE SCRIPT in help. Does anyone have any ideas on how to rectify this? I'm not sure how to go along with @extended = 1 as the help file just says it is the COM error code. Thanks
Xenio Posted May 9, 2019 Author Posted May 9, 2019 Error in help is specified as: 3 - Error occurred when opening specified document. @extended is set to the COM error code
Xenio Posted May 9, 2019 Author Posted May 9, 2019 This is now resolved. I used: _DebugSetup("Word Debug Window", True, 1, "", True) _DebugCOMError(1) ; Register a default COM error handler to grab Word COM errors and write the messages to the Debug window to grab the COM Error codes and found out from a bit of googling that #RequireAdmin was needed. I added that in and now it opens. Weird :X
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