egalvez Posted March 1, 2005 Share Posted March 1, 2005 Hi. I want to use AutoIt3 to open a Excel to do list spreadsheet every hour. That's easy enough to set up in conjunction with another program that will open an exe periodically, like KeyText or Peter's Ultimate Alarm Clock. My problem is that if Excel is already open when the to do list spreadsheet opens each hour, two instances of Excel will now be open and I'll get a File in use - locked for editing error. I don't want two instances of Excel to open. If Excel is already open when the hourly time comes, I want the to do list spreadsheet to simply open as another workbook in Excel. I know how to use AutoIt to test what apps are open, but how can I tell AutoIt that if Excel is already open, don't open Excel again, just open my to do list spreadsheet? Thank you. Link to comment Share on other sites More sharing options...
Lanturn Posted March 2, 2005 Share Posted March 2, 2005 If you know how to check for an open Excel window, the rest is easy... Just set it as the active window, then send Ctrl+O for open, input the path of the spreadsheet and hit {ENTER}... You may want to block keyboard/mouse input during that time as it may interfere with the keyboard shortcuts your script is sending... If WinExists("Excel") Then BlockInput(1);Blocks user input WinActivate("Excel");Activates the Excel window Send("^o");Sends Ctrl+O command to display the open file dialog WinWaitActive("Open");Wait for the open file dialog to show Send($path);Input the filename (with path) Send("{ENTER}");Simulates the Open button press BlockInput(0);Releases block on user input EndIf Hope this helps Matt Link to comment Share on other sites More sharing options...
egalvez Posted March 2, 2005 Author Share Posted March 2, 2005 Hi. I figured it could be done by sending keys, but I was hoping that somehow it could be done transparently without the interruption of having to send keys. Thank you, anyway. Link to comment Share on other sites More sharing options...
jdickens Posted March 2, 2005 Share Posted March 2, 2005 How about this: You can check for text in an window titled Excel; something like: if WinExists("Excel", "MyToDoList.xls") then ; Don't open to do list; it's already open. ; Send an Alt W for Window and then the number of the document ; Use Window Spy and you'll determine the filenames of all the documents can each be ascertained as a window number else ;send some hotkeys to Excel to open that bad puppy! ;send a Ctrl O and a path and an enter. ;if you call a couple of flashes (the quick Open dialog) an interruption then you should also consider the to do list popping up unexpectedly an interruption too. endif J If I am too verbose, just say so. You don't need to run on and on. Link to comment Share on other sites More sharing options...
Blue_Drache Posted March 2, 2005 Share Posted March 2, 2005 (edited) Also, keep in mind that the office assistant can play hob with scripts. I like to disable it with this handy function: ; Kill the Office Assistant!!! This is a function to disable it temporarialy. ; It will be re-enabled on any normal program exit if it was enabled previously. $CurrentAssist = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Assistant", "AsstState") $killassist = Hex(38, 8) If Not $CurrentAssist = $killassist Then $restoreAssit = Dec($CurrentAssist) $restoreAssit = Hex($restoreAssit, 8) RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Assistant", "AsstState", "REG_DWORD", $killassist) $office = 1 EndIf And then re-enable it at the end of the script with: If $office = 1 Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\Assistant", "AsstState", "REG_DWORD", $restoreAssist) EndIf I always hated that dorky paper-clip anyway. Edited March 2, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
bshoenhair Posted March 2, 2005 Share Posted March 2, 2005 (edited) Tested on WinXP and this doesn't open another instance of Excel. Use @ComSpec to open your spreadsheet. Run(@ComSpec & ' /c "' & @DesktopDir & '\test.xls"','',@SW_HIDE) Or Use _ShellExecuteDllCall('"' & @DesktopDir & '\test.xls"','','',0) Func _ShellExecuteDllCall($sCmd, $sVerb, $sArg, $sFolder) Local $aRet $aRet = DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", $sVerb, _ "string", $sCmd, "string", $sArg, "string", $sFolder, "long", @SW_SHOWNORMAL) Return $aRet If $aRet[0] > 32 Then Return 1;All Ok Else Return 0;Problems EndIf EndFunc Edited March 2, 2005 by bshoenhair Link to comment Share on other sites More sharing options...
egalvez Posted March 31, 2005 Author Share Posted March 31, 2005 Thank you all for the suggestions. I've incorporated bshoenhair's as follows:Run(@ComSpec & ' /c "c:\data\eric\2do.xls"','',@SW_HIDE)and it works great. 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