proc main integer iTask, iWindow, iStatus = 0 string sTaskName if winactivate "Microsoft Excel - test.xls" ;File already loaded, just bring Excel to the front iStatus = 1 elseif winactivate "Microsoft Excel" ;Excel active, but no files loaded open_spreadsheet() iStatus = 1 elseif winactivate "Microsoft Excel - Book1" ;Excel open with default Book1 open_spreadsheet() iStatus = 1 elseif firsttask iTask ;Search list of tasks for excel.exe taskname iTask sTaskName ;and load our file if Excel is active if strnicmp sTaskName "excel.exe" 9 taskwin iTask iWindow winactivate iWindow open_spreadsheet() iStatus = 1 endif while nexttask iTask taskname iTask sTaskName if strnicmp sTaskName "excel.exe" 9 taskwin iTask iWindow winactivate iWindow open_spreadsheet() iStatus = 1 endif endwhile endif if iStatus == 0 ;Excel not active run "c:\program files\microsoft office\office\excel.exe c:\test.xls" endif endproc proc open_spreadsheet ;Procedure to open spreadsheet using sendkey commands mspause 100 sendkey ALT 'F' sendkey 'O' mspause 100 sendkeystr "c:\test.xls" mspause 100 sendkey ALT 'O' endproc