Jump to content

Problems with _ExcelCloseBook


cag8f
 Share

Recommended Posts

_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

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

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 by MrMitchell
Link to comment
Share on other sites

-- 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 by cag8f
Link to comment
Share on other sites

-- 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

  • 1 year later...

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...