maniootek

_ExcelOpen() cause COM error

4 posts in this topic

#1 ·  Posted

When I run this code I got COM error.

#include <Excel.au3>

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $oExcel = _Excel_Open()

Func _ErrFunc($oError)
    local $message
    $message &= "COM Error!" & @CRLF & @CRLF
    $message &= "scriptname: " & @ScriptName & @CRLF & @CRLF
    $message &= "number: " & $oError.number & @CRLF
    $message &= "windescription: " & $oError.windescription & @CRLF
    $message &= "source: " & $oError.source & @CRLF
    $message &= "description: " & $oError.description & @CRLF
    $message &= "helpfile: " & $oError.helpfile & @CRLF
    $message &= "helpcontext: " & $oError.helpcontext & @CRLF
    $message &= "lastdllerror: " & $oError.lastdllerror & @CRLF
    $message &= "scriptline: " & $oError.scriptline & @CRLF
    MsgBox(16, @ScriptName, $message)
EndFunc

Any idea what is wrong?

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Works as designed!
_Excel_Open tries to connect to an already running instance of Excel. If there is none you get a COM error. This error is handled by _Excel_Open, which means that the function then starts a new instance of Excel.

Added: if you run the latest version of AutoIt then there is no need for a COM error handler in the main script as each UDF function calls its own COM error handler.

Edited by water
Description how the latest version of AutoIt handles COM errors.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

10 hours ago, Jos said:

Care to share what that error is or do you want us to guess? ;)

Jos

sorry for that, COM error just show "scriptline 65" error, nothing more

 

10 hours ago, water said:

Works as designed!
_Excel_Open tries to connect to an already running instance of Excel. If there is none you get a COM error. This error is handled by _Excel_Open, which means that the function then starts a new instance of Excel.

Added: if you run the latest version of AutoIt then there is no need for a COM error handler in the main script as each UDF function calls its own COM error handler.

thank you for information. Now I used this code:

_Excel_Open(default, default, default, default, True)

and there is no more com error

Edited by maniootek

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now