HighlanderSword Posted April 1, 2017 Posted April 1, 2017 (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 April 1, 2017 by HighlanderSword
Xandy Posted April 1, 2017 Posted April 1, 2017 (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 April 1, 2017 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker)
HighlanderSword Posted April 1, 2017 Author Posted April 1, 2017 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
InunoTaishou Posted April 1, 2017 Posted April 1, 2017 #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
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