Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_ExcelBookClose: why is Excel not closing?


  • Please log in to reply
3 replies to this topic

#1 Akshay07

Akshay07

    Prodigy

  • Active Members
  • PipPipPip
  • 163 posts

Posted 29 December 2009 - 05:37 PM

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, 29 December 2009 - 05:44 PM.








#2 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 29 December 2009 - 07:34 PM

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

#3 Akshay07

Akshay07

    Prodigy

  • Active Members
  • PipPipPip
  • 163 posts

Posted 29 December 2009 - 08:03 PM

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, 29 December 2009 - 10:04 PM.


#4 microera

microera

    Wayfarer

  • Active Members
  • Pip
  • 70 posts

Posted 11 January 2010 - 07:11 PM

yes! ;)
I test with AutoIt v3.3.2.0 and on one computer
_ExcelBookClose($oExcel)
work ok
but on another NOT!

Where is problem?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users