LurchMan Posted January 21, 2010 Share Posted January 21, 2010 Hey everyone - I'm working on a simple excel script that's going to start Excel, run a macro and wait for the next instance of excel to start. When the next instance starts I want it to close the first one and exit the script. What I have: #include <excel.au3> Opt ("WinTitleMatchMode", 2) $oExcel = _ExcelBookOpen (@ScriptDir & "\macro.xls", 0) $oExcel.Run ("Start") While 1 Sleep (100) If BitAND(WinGetState("Microsoft Excel"), 2) Then _ExcelBookClose ($oExcel, 0, 0) Exit EndIf WEnd This works, except it closes the entire excel program (both workbooks) - I only want it to close the first one. Thanks for any and all help. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
reb Posted January 22, 2010 Share Posted January 22, 2010 (edited) Hi instead of If BitAND(WinGetState("Microsoft Excel"), 2) Then maybe If BitAND(WinGetState("Microsoft Excel - macro.xls"), 2) Then not tested REB Edit put in first book name Edited January 22, 2010 by reb MEASURE TWICE - CUT ONCE Link to comment Share on other sites More sharing options...
zfisherdrums Posted January 22, 2010 Share Posted January 22, 2010 LurchMan, Untested and possibly brittle, but should work in theory. Let me know if it doesn't. #include <excel.au3> Opt ("WinTitleMatchMode", 2) Func GetNumExcelProcess() $_aProcesses = ProcessList( "Excel.exe" ) return $_aProcesses[0][0] EndFunc $oExcel = _ExcelBookOpen (@ScriptDir & "\macro.xls", 0) $oExcel.Run ("Start") ; Establish a baseline number of known Excel processes $iNumExcelProcess = GetNumExcelProcess() ; Periodically test for changes in the number of Excel processes While ( $iNumExcelProcess = GetNumExcelProcess() ) Sleep (100) WEnd _ExcelBookClose ($oExcel, 0, 0) Exit Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
LurchMan Posted January 23, 2010 Author Share Posted January 23, 2010 Reb - Thank you for your suggestion, I've tried that also but it doesn't close just that window still. Zach - Thank you for your help I will test it later. It looks like it should work to me. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. 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