cag8f Posted December 9, 2010 Share Posted December 9, 2010 _ExcelCloseBook() has been working just fine for me for a few weeks now; it would close the Excel file I had previously opened. But all of a sudden it stopped working as expected. Here is my test code (taken from the help file): #include <Excel.au3> $oExcel = _ExcelBookNew() ; Example 1 - Create a Microsoft Excel window MsgBox ( 0, "", _ExcelBookClose($oExcel)) Exit Excel is opened and a new file is created. However upon script completion Excel stays open. Furthermore I cannot click anywhere in the window, even to close it. I can't even move the window (I can resize it though). I can only close it by killing it in task manager. Also, the message box returns 0, indicating that the file close failed. Probably something stupid, but any thoughts? Link to comment Share on other sites More sharing options...
MrMitchell Posted December 9, 2010 Share Posted December 9, 2010 @error would give you a little more info. I have the same problem sometimes, has to do with an existing excel.exe process created by another script or something else that opened a workbook but didn't close it properly. Link to comment Share on other sites More sharing options...
cag8f Posted December 9, 2010 Author Share Posted December 9, 2010 Task manager does not show any other Excel processes running. I'm a noob; what is the syntax for using @error? Can I simply put it in a message box? Link to comment Share on other sites More sharing options...
MrMitchell Posted December 9, 2010 Share Posted December 9, 2010 Task manager does not show any other Excel processes running. I'm a noob; what is the syntax for using @error? Can I simply put it in a message box? Something like this should work: #include <Excel.au3> $oExcel = _ExcelBookNew() ; Example 1 - Create a Microsoft Excel window $excelBookCloseResult = _ExcelBookClose($oExcel) $excelBookCloseErr = @error MsgBox ( 0, "", "Result: " & $excelBookCloseResult & @CRLF & "Error: " & $excelBookCloseErr) Exit Link to comment Share on other sites More sharing options...
cag8f Posted December 9, 2010 Author Share Posted December 9, 2010 I ran that and got Result = 0 Error = 1. The same problem with the Excel workbook was exhibited. Link to comment Share on other sites More sharing options...
MrMitchell Posted December 9, 2010 Share Posted December 9, 2010 (edited) Can you close Excel with this as the last line before exit?... $oExcel.Application.Quit Edit: Just trying anything until someone that has a better idea sees your thread Edited December 9, 2010 by MrMitchell Link to comment Share on other sites More sharing options...
cag8f Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks for your help. Yes that did close Excel, but I'd obviously like for _ExcelCloseBook to work. Might there be some open workbooks that are hidden somehow? I've rebooted the machine a few times. Link to comment Share on other sites More sharing options...
MrMitchell Posted December 9, 2010 Share Posted December 9, 2010 (edited) Yah put this in to see how many workbooks are present before your _ExcelBookClose() MsgBox(0, "", $oExcel.Application.Workbooks.Count) Add: Also, maybe change your ExcelBookClose statement to enable alerts to see what might be holding it up: $excelBookCloseResult = _ExcelBookClose($oExcel, 1, 1) Edited December 9, 2010 by MrMitchell Link to comment Share on other sites More sharing options...
cag8f Posted December 9, 2010 Author Share Posted December 9, 2010 (edited) -- Inserting the check for open workbooks before the _ExcelCloseBook returns 1. -- _ExcelBookCloseResult returns 0. When I enable message alerts in _ExcelBookClose, Excel still stay open, but I can now click around in the window and even close it from the window. While if I disable message alerts, I am not able to do so. Curious. Edited December 9, 2010 by cag8f Link to comment Share on other sites More sharing options...
MrMitchell Posted December 9, 2010 Share Posted December 9, 2010 -- Inserting the check for open workbooks before the _ExcelCloseBook returns 1.-- _ExcelBookCloseResult returns 0.When I enable message alerts in _ExcelBookClose, Excel still stay open, but I can now click around in the window and even close it from the window. While if I disable message alerts, I am not able to do so. Curious.Yea if you check the code for that function it first checks how many workbooks are open and if only 1 it will quit the app. If more than 1 it just closes that workbook that you're on. Something like that Link to comment Share on other sites More sharing options...
cag8f Posted December 9, 2010 Author Share Posted December 9, 2010 Still not resolved, but a workaround is in place. Thanks for all the help. Link to comment Share on other sites More sharing options...
Gorby7 Posted March 9, 2012 Share Posted March 9, 2012 I know this is old and a workaround exists, but I've found a simpler workaround that may help others. Whatever variable you use with _ExcelBookNew() or _ExcelBookOpen() must be set to zero after using _ExcelBookClose(). For example: $oExobject=_ExcelBookNew() ;...do stuff _ExcelBookClose() $oExobject=0 This will immediately end the EXCEL.EXE process and allow you to maniputlate the saved Excel file with other functions. 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