Jump to content

Closing Excel Files


Recommended Posts

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

 

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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