Jump to content
montyali

Closing Excel Files

Recommended Posts

montyali

Hi, need some help closing Excel workbooks. Found below example and it works really well, except under one condition...when a cell had been double-clicked in for editing or for copying data. In those cases, the workbook remains open and I cannot even write data to it. 

 

How can I modify below to deselect this cell...doesn’t matter how, just want to close (and save sheet). 

 

Please help!

 

 

Example I found on web —posted by Water—

 

#include <Excel.au3>

Global $oExcel = _Excel_Open(False) ; Connect to Excel and remain invisible

Global $aWorkbooks = _Excel_BookList($oExcel) ; Return a 2D array containing a list of open workbooks

For $i = 0 To UBound($aWorkbooks, 1) - 1 ; Close all found workbooks

    _Excel_BookClose($aWorkbooks[$i][0], False)

Next

_Excel_Close($oExcel, Default, True) ; Close the Excel instance even when not created by the script

 

Share this post


Link to post
Share on other sites
water

Set parameter $bInteractive when calling _Excel_Open to False so the user can not interact with Excel while your script is running.

BTW: Could you please use a smaller font? Makes reading your posts much easier ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
montyali
Posted (edited)

Not sure what happen to my post there, why so big LOL...sorry

Also, can u please update the script to show it as an example...your help will be much appreciated  

I also meant workbook that was left open before the script starts (never closed by mistake)...And this will disregard the selected blinking cell and close book anyway. Sorry but I have not used Autoit much recently and very very rusty  

 

Edited by montyali

Share this post


Link to post
Share on other sites
water

I haven't found a way to connect to a workbook being edited by the user. It seems the user first has to finish his edit before the script can gain full control.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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

×