Jump to content

_ExcelBookClose: why is Excel not closing?


Akshay07
 Share

Recommended Posts

Hi,

I have a problem with a piece of code.

What I want to achieve is the following

1/ Open an excel file

2/ Save it with another name. It works fine til that point

3/ Closing it --> This does not work

Here is the piece of script

$oExcel = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls")  ; this works
_ExcelBookClose($oExcel, 0, 0) ; Excel is not closed

I also tried

Here is the piece of script

$oExcel = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls")  ; this works
_ExcelBookClose($oExcel, 0, 1) ; Excel is not closed

to enable Excel message alert but I don't get any alert.

PS: I know I could kill the process, but I would like to understand why ExcelBookClose does not work in the script

Edited by Akshay07
Link to comment
Share on other sites

You are destroying your $oExcel object reference or using the wrong variable when you save the return value from _ExcelBookSaveAs() over it:

$iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls")
If $iRET Then 
      _ExcelBookClose($oExcelTemplate, 0, 1)
Else
      MsgBox(16, "Error", "Failed to save changes.")
EndIf

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You are destroying your $oExcel object reference or using the wrong variable when you save the return value from _ExcelBookSaveAs() over it:

$iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls")
If $iRET Then 
      _ExcelBookClose($oExcelTemplate, 0, 1)
Else
      MsgBox(16, "Error", "Failed to save changes.")
EndIf

;)

Thank you for your test code.

I was very careful to not reuse an existing object, but well, as you know, one can always miss something.

So I did implement your piece of script and I did not get any error message after the

$iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls")

Therefore, I still have a problem.

Edited by Akshay07
Link to comment
Share on other sites

  • 2 weeks later...

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