MichaelCrawley Posted February 27, 2023 Share Posted February 27, 2023 (edited) @moderators if I posted in the wrong place I do apoligize. I am not sure if the format of my script is correct or not I am kind of new autoIT so excuse my format errors. I essientially crate the same script to close chrome.exe and it works w\o issue. I wanted make sure the command work and if just copy TASKKILL /F /IM excel.exe /T in a command prompts it work w\o issue. I am a NOOB at this so I am sure I am getting stuff wrong. If you could explain where I am going wrong it would be very helpful. So these are snippets of my scripts: Global $exitExcel ;Button name "Close Excel" Global $idButton_closeExcel = GUICtrlCreateButton("Close Excel", 10, 90, 85, 25) GUICtrlSetBkColor(-1, 0x99B4D1) ;closes excel Case $idButton_closeExcel $exitExcel() ;Function to kill excel Func exitExcel() $runString = StringFormat("TASKKILL /F /IM excel.exe /T") $run = Run($runString, "", @SW_HIDE) EndFunc Edited February 27, 2023 by MichaelCrawley clerification Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted February 27, 2023 Share Posted February 27, 2023 Hi @MichaelCrawley, what exactly is it what you want? Simply close the process "excel.exe"? Or do you want to close it by a button on your GUI? Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
water Posted February 27, 2023 Share Posted February 27, 2023 I suggest to use the Excel UDF to gracefully close Excel. By killing a process you might create problems with unsaved files remaining in an undefined state etc. This is true for every application. SOLVE-SMART 1 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 Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 27, 2023 Author Share Posted February 27, 2023 Correct yes I am using a gui and the botton should close excel Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 27, 2023 Author Share Posted February 27, 2023 So if I wanted to use Excel UDF how would use it? I read up on it and there it seems there is a lot of files you have to save and edit the rigistry but it wasn't clear how to do it. Link to comment Share on other sites More sharing options...
SOLVE-SMART Posted February 27, 2023 Share Posted February 27, 2023 Just now, MichaelCrawley said: Correct yes I am using a gui and the botton should close excel So the script above is only a snippet or your complete script? Like @water suggest, include the Excel UDF and use the _Excel_Close() function. Best regards Sven Stay innovative! Spoiler 🌍 Au3Forums 🎲 AutoIt (en) Cheat Sheet 📊 AutoIt limits/defaults 💎 Code Katas: [...] (comming soon) 🎭 Collection of GitHub users with AutoIt projects 🐞 False-Positives 🔮 Me on GitHub 💬 Opinion about new forum sub category 📑 UDF wiki list ✂ VSCode-AutoItSnippets 📑 WebDriver FAQs 👨🏫 WebDriver Tutorial (coming soon) Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 27, 2023 Share Posted February 27, 2023 Definitely check out the Excel UDF, from water's signature: 2 minutes ago, water said: Excel - Example Scripts - Wiki And: https://www.autoitscript.com/wiki/Excel_UDF https://www.autoitscript.com/autoit3/docs/libfunctions/Excel Management.htm However, to just close Excel immediately, look at using ProcessClose(), WinClose(), or WinKill(). Also for your script, there's no reason to use StringFormat, you're not passing any formatting into it, you can just do this directly: ; $runString = "TASKKILL /F /IM excel.exe /T" ; You can also do this, unless you're actually performing some formatting with StringFormat, there's no reason to use it. $run = Run("TASKKILL /F /IM excel.exe /T", "", @SW_HIDE) We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Solution water Posted February 27, 2023 Solution Share Posted February 27, 2023 Quite easy: #include <Excel.au3> Global $oExcel = _Excel_Open() ; Starts a new Excel instance or connects to an already running instance If @error Then ... ; Write an Error-Message and Exit _Excel_Close($oExcel, False, True) ; Does not save any open workbooks and closes the Excel instance If @error Then ... ; Write an Error-Message and Exit MichaelCrawley 1 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 Link to comment Share on other sites More sharing options...
MichaelCrawley Posted February 27, 2023 Author Share Posted February 27, 2023 If I use UDF is all I do? To use UDF would just put this in a function? ;closes excel Func closeExcel() _Excel_Close Endfunc Link to comment Share on other sites More sharing options...
water Posted February 27, 2023 Share Posted February 27, 2023 No, you need all the statements I have posted above. #include <Excel.au3> ; Copies the Excel UDF code to your script Global $oExcel = _Excel_Open() ; Starts a new Excel instance or connects to an already running instance If @error Then ... ; Here you insert the code to execute when Excel is not installed on the machine or other erorrs occure _Excel_Close($oExcel, False, True) ; Does not save any open workbooks and closes the Excel instance If @error Then ... ; Here you insert the code to execute when there is an error when closing Excel #include should be at the top of your script, the rest can be put into a function. 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 Link to comment Share on other sites More sharing options...
MichaelCrawley Posted March 14, 2023 Author Share Posted March 14, 2023 I forgot to say thank your the clerification on this. Link to comment Share on other sites More sharing options...
water Posted March 14, 2023 Share Posted March 14, 2023 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 Link to comment Share on other sites More sharing options...
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