Alt+F, Alt+O not working with excel

Asked by Rahul

Using the following commands to get to open file box after launching excel. In the app this can be acheived by pressing Alt+F followed by Alt+O:

openApp("C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE")
type("F", KEY_ALT)
type("O", KEY_ALT)

Open excel works fine but nothing happens after that. Get the following sikuli message:

[sikuli] type: 'F' +8
[sikuli] type: 'O' +8

Can somebody please help and point to what might I be doing wrong? I am using Vista and Excel 2003

Thanks,
Rahul

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Rahul
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

I think you have to use lowercase letters
type("f", KEY_ALT)
....

If you use the keyboard, you are just holding Alt and then clicking the f-key.

type("F", ALT_KEY) is the same as
type("f", KEY_ALT | KEY_SHIFT) which should not do, what you want - if anything.

Revision history for this message
Rahul (rahulprakash) said :
#2

Raiman, Tnx for helping

I have tried with lowercase letters too, and it gives me the same behavior :(

type("f", ALT_KEY) gets similar sikuli message
[sikuli] type: 'f' +8

Rahul

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Just tried on Win7 and Excel 2007. Worked well (Alt-r-x, that triggers cutting function in start ribbon).
(on a WinXP with Excel 2003 (sorry, there is no Java and therfor no Sikuli) I found, that both "F" and "f" + Alt open the file menu.

So I think, it has to do with having the focus.

Try the following, to test wether the type works:

Manually:
open Excel
click one cell, so that it is marked

In Siculi:
switchApp("excel") # which is sufficient to get an opened Excel to foreground
type("f", KEY_ALT) # the file menu should open

If it happens now, then it may be, that after your openApp() you have to click() first somewhere in the sheet.

Revision history for this message
Rahul (rahulprakash) said :
#4

Thanks RaiMan, your brainstroming has helped solved this issue for me.

Unfortunately for me switchApp doesn't seem to work at all. So I continued working with openApp (will put another question for help on that one). Following code worked like a charm.

openApp("C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE")
sleep(1)
type("f", KEY_ALT)
sleep(1)
type("o")

The issue was that sikuli was sending commands before excel was ready to accept them. So a sleep() helped Excel be in a state to receive commands and respond as expected.

Your suggestion of click() did work too, but I was trying to avoid click() if I have shortcut keys to work with. But that exercise of click() gave me the idea that sikuli might actually need to wait a bit before sending commands to excel.

Thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

congrats. you got it.

did not think about sleep(), since it was running on my system. but finding out about sufficient delays before next action is vital for Sikulki scripts (e.g. wait() and untilNotExist()).

openApp() and switchApp() on Windows have some problems, but what seems to work, is that when an app has open windows (started the app with what means ever), it is possible, to get the window frontmost with e.g. switchApp("excel"), if excel is somewhere in the title of the window.

Another tip: if you are using type() more often in your scripts together with sleep() (and other commands of course), latest when a sequence is running, you can write:
sleep(1); type("f", KEY_ALT); sleep(1); type("o")
on one line.

Revision history for this message
Rahul (rahulprakash) said :
#6

Thanks for the tip. That will help code way more readable.

And now I won't bang my head against switchApp() much. openApp() seems to work fine. I have tried on a Vista and a Win7 machine.

Thanks,
Rahul