Jump to content

Excel UDF

Recommended Posts




When I use the Excel UDF , with the snippet below, I want to leave Excel Open and let the user decide what to do with the file.

However after the user closes the excel file, their is still an instance of Excel running in task Manager , not visible to users

How do I code the script so that once the user closes excel it also closes the reference to Excel in the still running script and not have to pause the script so

that it can continue to run


Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, "D:\review.xlsx")


Edited by HighlanderSword

Share this post

Link to post
Share on other sites

Here is a modified example I'm using from the help file.

Note: the _Excel_Close($oExcel)

$oExcel = _Excel_Open(True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "write_spreedsheat", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookNew($oExcel)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "write_spreedsheat", "Error creating the new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

Is this what you need?

Edited by Xandy

Share this post

Link to post
Share on other sites



If I add a Message box at the end of the above script , and then go and close excel, there is still an excel open in task manager , this is the issue I'm trying to resolve

Thanks for trying to Assist

Share this post

Link to post
Share on other sites
#include <Excel.au3>
#include <MsgBoxConstants.au3>

Global $oExcel = _Excel_Open()
Global $oWorkbook = _Excel_BookNew($oExcel)

If (@error) Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: Events Example", "Error opening workbook '_Excel2.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

ObjEvent($oWorkbook, "Workbook_")

While (True)

Func Close()
    _Excel_Close($oExcel, False, True)
    exit 0

Volatile Func Workbook_BeforeClose(ByRef $bCancel)
    #forceref $bCancel
EndFunc   ;==>Workbook_BeforeClose

How about that?


Didn't even know there was a way to capture object events in an autoit script. I've been using Excel and VBA for a few months now lol

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


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.