HighlanderSword

Excel UDF

4 posts in this topic

#1 ·  Posted (edited)

Hello,

 

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



#2 ·  Posted (edited)

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)
        _Excel_Close($oExcel)
        Exit
    EndIf

Is this what you need?

Edited by Xandy

I am not a lawyer.  (-_-) Xandy About  (^o^) Discord - Xandy Programmer

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hello,

 

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

#4 ·  Posted

#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)
    _Excel_Close($oExcel)
    Exit
EndIf

ObjEvent($oWorkbook, "Workbook_")

While (True)
    Sleep(100)
WEnd

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

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

How about that?

Sauce

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