montyali Posted March 18, 2018 Posted March 18, 2018 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
water Posted March 18, 2018 Posted March 18, 2018 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 2024-07-28 - Version 1.6.3.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 (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
montyali Posted March 18, 2018 Author Posted March 18, 2018 (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 March 18, 2018 by montyali
water Posted March 18, 2018 Posted March 18, 2018 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 2024-07-28 - Version 1.6.3.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 (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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now