Champak Posted June 15, 2023 Share Posted June 15, 2023 I'm getting a COM error when starting word and the only way to fix it is to manually start word. I made a spell checker from this: The problem is every once in a while word will pop up 15 windows or so of unsaved documents for me to save or exit spawned from this app. When I do that and close all of them out I get the following COM error every time I start my script when it hits: Global $oWordApp = _Word_Create(False) Besides forcing word to execute and close upon WordCreate throwing that error (if that will fix the problem), is there some other way to fix this? Link to comment Share on other sites More sharing options...
Andreik Posted June 15, 2023 Share Posted June 15, 2023 Show us some code to see what crash at line 53. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Champak Posted June 16, 2023 Author Share Posted June 16, 2023 (edited) That's the odd thing, it's just an include file: #include <EditConstants.au3> on line 53. This comes before the call to the WordCreate. Has nothing to do with the COM as far as I saw, I couldn't figure out the relationship. I can't readily reproduce Word glitching out and telling me to do something with the documents, so it's hard to actively TS this. Edited June 16, 2023 by Champak Link to comment Share on other sites More sharing options...
Andreik Posted June 16, 2023 Share Posted June 16, 2023 If you can't figure it out with code, imagine us without seeing any code. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 16, 2023 Moderators Share Posted June 16, 2023 Have to agree with Andreik, you have been a member long enough to know the community crystal ball is in the shop. Post a reproducer; help us help you. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
argumentum Posted June 16, 2023 Share Posted June 16, 2023 #include <MsgBoxConstants.au3> #include <Word.au3> #include <EditConstants.au3> ; no error that I can see ; Create a new Word object _Word_Create() If @error <> 0 Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_Create Example", _ "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) If @extended = 1 Then MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_Create Example", "MS Word was not running when _Word_Create was called.") Else MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_Create Example", "MS Word was already running when _Word_Create was called.") EndIf no hard. This does not show an error @Champak Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Solution Champak Posted June 16, 2023 Author Solution Share Posted June 16, 2023 I get both of your points, but I didn't put any code because 1/ I know it had absolutely nothing to do with the rest of the app, 2/ It's 10,000 lines of code in the app. If it did have something to do with the rest of the code I would't expect anyone to dig through it all to find the problem, and since I didn't know how to reproduce a shortened version to reproduce the problem because I didn't know what the problem was, giving a working sample code would not be possible. Either way argumentum pointed me in the right direction to dig with that error check. It turns out I HAVE to put the second parameter as True if I don't already have Word running to prevent that COM error, or suppress it in the com error handler function. The spell check works with word regardless, but the COM error still comes up. That is not clear to me the way the help file is worded...especially since the excel udf doesn't work like that. Either way, it's fixed now. Thanks. argumentum 1 Link to comment Share on other sites More sharing options...
Andreik Posted June 16, 2023 Share Posted June 16, 2023 8 minutes ago, Champak said: I get both of your points, but I didn't put any code because 1/ I know it had absolutely nothing to do with the rest of the app If that would be true than you might reproduce the error fairly easy. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
argumentum Posted June 16, 2023 Share Posted June 16, 2023 1 hour ago, Champak said: It turns out I HAVE to put the second parameter as True if I don't .... Either way, it's fixed now. Thanks. mark it solved to your findings.for the next guy reading looking for a solution Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
water Posted June 17, 2023 Share Posted June 17, 2023 If you set the second parameter to True ALWAYS a new instance of Word is created even when Word is already running. If _Word_Create is started with default values it tries to connect to a running instance. When there is none you get the COM error you posted above. Call _Word_Create with default values and ignore the first COM error you get from this function. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Champak Posted June 17, 2023 Author Share Posted June 17, 2023 Yeah I get that, that second parameter doesn't make that much sense to me. I just don't want that initial error regardless. I did the following instead. Global $WordComGlitch = True Global $oWordApp = _Word_Create(False) $WordComGlitch = False Func ErrFunc($oError) If $WordComGlitch = True Then Return $oExcel.ScreenUpdating = True MsgBox($MB_OK, "A COM Error was intercepted!", _ "Number: 0x" & Hex($oError.number, 8) & @CRLF & _ "Description: " & $oError.windescription & @CRLF & _ "At line: " & $oError.scriptline) Return EndFunc ;==>ErrFunc 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