Herb191 Posted December 30, 2010 Share Posted December 30, 2010 The following works on one of my computers running XP but when I run it on a computer with Windows 7 I get errors. Any ideas on how I can fix it? The example script in AutoIt’s help file also does not work on the computer with Windows 7. I checked the include file and the word.au3 file is there. #include <Word.au3> $oWordApp = _WordCreate("", 0, 0) _WordQuit($oWordApp, 0) --> Word.au3 Error from function _WordDocAdd, $_WordStatus_InvalidObjectType --> Word.au3 Error from function _WordQuit, $_WordStatus_InvalidObjectType Link to comment Share on other sites More sharing options...
ZacUSNYR Posted December 30, 2010 Share Posted December 30, 2010 Do you have Word? Link to comment Share on other sites More sharing options...
Herb191 Posted December 30, 2010 Author Share Posted December 30, 2010 Do you have Word? Yes Link to comment Share on other sites More sharing options...
ZacUSNYR Posted December 30, 2010 Share Posted December 30, 2010 Just making sure, what version of Word? Does everything appear to be functioning properly with it? Link to comment Share on other sites More sharing options...
Herb191 Posted December 30, 2010 Author Share Posted December 30, 2010 (edited) Just making sure, what version of Word? Does everything appear to be functioning properly with it?Microsoft Office Word 2010. Everything seems to be working fine. Edited December 31, 2010 by Herb191 Link to comment Share on other sites More sharing options...
Zedna Posted December 30, 2010 Share Posted December 30, 2010 Use _WordErrorHandlerRegister() to register a user error handler. This way you can see the full error description. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Herb191 Posted December 30, 2010 Author Share Posted December 30, 2010 Use _WordErrorHandlerRegister() to register a user error handler.This way you can see the full error description.Thanks, I won’t have access to that computer again until tomorrow but I will try it. Link to comment Share on other sites More sharing options...
Herb191 Posted January 5, 2011 Author Share Posted January 5, 2011 I tried this and got the same thing. #include <Word.au3> _WordErrorHandlerRegister() $oWordApp = _WordCreate("", 0, 0) _WordQuit($oWordApp, 0) I installed office 2007 to see if that would fix it and I still get the same thing. Link to comment Share on other sites More sharing options...
Zedna Posted January 5, 2011 Share Posted January 5, 2011 You must use "your own error handler function" which contains Messagebox() with all the errors. See examples. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Herb191 Posted January 5, 2011 Author Share Posted January 5, 2011 (edited) You must use "your own error handler function" which contains Messagebox() with all the errors. See examples. Perhaps I am not understanding something correctly. I tried running this and got the same thing. #include <Word.au3> Global $oWordErrorHandler _WordErrorHandlerRegister("MyErrFunc") $oWordErrorHandler = _WordCreate("", 0, 0) _WordErrorHandlerDeRegister() _WordQuit($oWordErrorHandler, 0) Exit Func MyErrFunc() ; Important: the error object variable MUST be named $oWordErrorHandler $ErrorScriptline = $oWordErrorHandler.scriptline $ErrorNumber = $oWordErrorHandler.number $ErrorNumberHex = Hex($oWordErrorHandler.number, 8) $ErrorDescription = StringStripWS($oWordErrorHandler.description, 2) $ErrorWinDescription = StringStripWS($oWordErrorHandler.WinDescription, 2) $ErrorSource = $oWordErrorHandler.Source $ErrorHelpFile = $oWordErrorHandler.HelpFile $ErrorHelpContext = $oWordErrorHandler.HelpContext $ErrorLastDllError = $oWordErrorHandler.LastDllError $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0, "COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>MyErrFunc Edited January 5, 2011 by Herb191 Link to comment Share on other sites More sharing options...
Zedna Posted January 5, 2011 Share Posted January 5, 2011 #include <Word.au3> _WordErrorHandlerRegister("MyErrFunc") $oWord = _WordCreate("", 0, 0) _WordQuit($oWord, 0) _WordErrorHandlerDeRegister() Exit Func MyErrFunc() ; Important: the error object variable MUST be named $oWordErrorHandler $ErrorScriptline = $oWordErrorHandler.scriptline $ErrorNumber = $oWordErrorHandler.number $ErrorNumberHex = Hex($oWordErrorHandler.number, 8) $ErrorDescription = StringStripWS($oWordErrorHandler.description, 2) $ErrorWinDescription = StringStripWS($oWordErrorHandler.WinDescription, 2) $ErrorSource = $oWordErrorHandler.Source $ErrorHelpFile = $oWordErrorHandler.HelpFile $ErrorHelpContext = $oWordErrorHandler.HelpContext $ErrorLastDllError = $oWordErrorHandler.LastDllError $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0, "COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>MyErrFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Herb191 Posted January 5, 2011 Author Share Posted January 5, 2011 #include <Word.au3> _WordErrorHandlerRegister("MyErrFunc") $oWord = _WordCreate("", 0, 0) _WordQuit($oWord, 0) _WordErrorHandlerDeRegister() Exit Func MyErrFunc() ; Important: the error object variable MUST be named $oWordErrorHandler $ErrorScriptline = $oWordErrorHandler.scriptline $ErrorNumber = $oWordErrorHandler.number $ErrorNumberHex = Hex($oWordErrorHandler.number, 8) $ErrorDescription = StringStripWS($oWordErrorHandler.description, 2) $ErrorWinDescription = StringStripWS($oWordErrorHandler.WinDescription, 2) $ErrorSource = $oWordErrorHandler.Source $ErrorHelpFile = $oWordErrorHandler.HelpFile $ErrorHelpContext = $oWordErrorHandler.HelpContext $ErrorLastDllError = $oWordErrorHandler.LastDllError $ErrorOutput = "" $ErrorOutput &= "--> COM Error Encountered in " & @ScriptName & @CR $ErrorOutput &= "----> $ErrorScriptline = " & $ErrorScriptline & @CR $ErrorOutput &= "----> $ErrorNumberHex = " & $ErrorNumberHex & @CR $ErrorOutput &= "----> $ErrorNumber = " & $ErrorNumber & @CR $ErrorOutput &= "----> $ErrorWinDescription = " & $ErrorWinDescription & @CR $ErrorOutput &= "----> $ErrorDescription = " & $ErrorDescription & @CR $ErrorOutput &= "----> $ErrorSource = " & $ErrorSource & @CR $ErrorOutput &= "----> $ErrorHelpFile = " & $ErrorHelpFile & @CR $ErrorOutput &= "----> $ErrorHelpContext = " & $ErrorHelpContext & @CR $ErrorOutput &= "----> $ErrorLastDllError = " & $ErrorLastDllError MsgBox(0, "COM Error", $ErrorOutput) SetError(1) Return EndFunc ;==>MyErrFunc Hmmm when I run that I still get the same thing: --> Word.au3 Error from function _WordDocAdd, $_WordStatus_InvalidObjectType --> Word.au3 Error from function _WordQuit, $_WordStatus_InvalidObjectType +>20:29:22 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 1.781 Link to comment Share on other sites More sharing options...
Zedna Posted January 5, 2011 Share Posted January 5, 2011 You should see messagebox with more detailed error messages. Also don't quote previous posts if not needed. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Herb191 Posted January 5, 2011 Author Share Posted January 5, 2011 I know that’s what’s strange. I ran the exact code you posted for me and that’s what I got back. I tried something like that before as well and just thought I was using it wrong when I didnt get a messagebox. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 5, 2011 Developers Share Posted January 5, 2011 (edited) There is no COM error but a "check in the UDF error". Looks like ObjName() on line 1803 in word.au3 returns "" and @error=1 making the Word UDFs fail. This needs investigation... expandcollapse popupFunc __WordIsObjType(ByRef $o_object, $s_type) If Not IsObj($o_object) Then Return SetError($_WordStatus_InvalidDataType, 1, 0) ; Setup internal error handler to Trap COM errors, turn off error notification Local $status = __WordInternalErrorHandlerRegister() If Not $status Then __WordErrorNotify("Warning", "internal function __WordIsObjType", _ "Cannot register internal error handler, cannot trap COM errors", _ "Use _WordErrorHandlerRegister() to register a user error handler") Local $f_NotifyStatus = _WordErrorNotify() ; save current error notify status _WordErrorNotify(False) ; Local $s_Name = ObjName($o_object), $objectOK = False ; ObjName() returning "" Switch $s_type Case "wordobj" If __WordIsObjType($o_object, "application") Then $objectOK = True ElseIf __WordIsObjType($o_object, "window") Then $objectOK = True ElseIf __WordIsObjType($o_object, "document") Then $objectOK = True EndIf Case "application" If $s_Name = "_Application" Then $objectOK = True Case "document" If $s_Name = "_Document" Then $objectOK = True Case "documents" If $s_Name = "Documents" Then $objectOK = True Case "range" If $s_Name = "Range" Then $objectOK = True Case "window" If $s_Name = "Window" Then $objectOK = True Case "windows" If $s_Name = "Windows" Then $objectOK = True Case Else ; Unsupported ObjType specified Return SetError($_WordStatus_InvalidValue, 2, 0) EndSwitch $objectOK = True ; restore error notify and error handler status _WordErrorNotify($f_NotifyStatus) ; restore notification status __WordInternalErrorHandlerDeRegister() If $objectOK Then Return SetError($_WordStatus_Success, 0, 1) Else Return SetError($_WordStatus_InvalidObjectType, 1, 0) EndIf EndFunc ;==>__WordIsObjType I get the same as the OP on Win7 & Word2007. Edited January 5, 2011 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zedna Posted January 5, 2011 Share Posted January 5, 2011 When I run this on machine without Word installed I see messagebox with all the details and "wrong class name" in WinDescription. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Herb191 Posted January 5, 2011 Author Share Posted January 5, 2011 So is there any kind of workaround? Link to comment Share on other sites More sharing options...
Developers Jos Posted January 5, 2011 Developers Share Posted January 5, 2011 So is there any kind of workaround?Sure, disable the test temporary in Word.au3 or be patient till somebody has the time to sort out why the ObjName() function returns "" and @error = 1 and see what a proper fix is for the issue.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jandos Posted December 13, 2011 Share Posted December 13, 2011 You can try this: $wordApp = ObjCreate("Word.Application") $odoc = $wordApp.Documents.Open("") ;set the file to open $wordApp.visible = true sleep(2000) $wordApp.Quit Link to comment Share on other sites More sharing options...
kilian14 Posted December 15, 2011 Share Posted December 15, 2011 The last post worked for me. I tryed to create a word object with this code:$wordApp = ObjCreate("Word.Application")$odoc = $wordApp.Documents.Open("") ;set the file to open$wordApp.visible = truesleep(2000)$wordApp.Quit instead of usind the regular way and it worked. Not sure exactly where the mistake is but there is something to do with te COM objects of Microsoft word.#include <Word.au3>$oWord = _WordCreate("", 0, 0)_WordQuit($oWord, 0)I have two PCs with windows 7 and office 2010. One of them works just fine 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