ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What's the syntax error with this SendKeys code? (https://www.excelbanter.com/excel-programming/356299-whats-syntax-error-sendkeys-code.html)

Phil1982

What's the syntax error with this SendKeys code?
 
Why is it I can never understand the syntax mentioned in VBA Help?

I'm trying to use send keys at the moment and VBA help says as an example to
press Alt-F-X

Application.SendKeys("%fx")


So when I try and use Alt-F4 to exit WinAmp I type the code:

C:\Program Files\Winamp\winamp.exe.SendKeys("%{f4}")


and the moment I move to another line it comes up with the error message:
"Compile error: Expected: line number or statement or end of statement" and
it highlights the first "backslash \".

Judging from other code experts on this site have taught me, I would have
guessed "speach marks" should go around the path to the application, but that
doesn't work and VBA help doesn't suggest it.

Thanks in advance

Phil

Tom Ogilvy

What's the syntax error with this SendKeys code?
 
you wouldn't use winapp. You litterally use the word "Application" which
refers to Excel. Sendkeys sends the keystrokes to the active application
(the window with the focus). Just as a caution and it may not be an issue
for you, but If you do it right after a shell command, You might want need
to employ the WAIT command beforw sendkeys.



--
Regards,
Tom Ogilvy


"Phil1982" wrote in message
...
Why is it I can never understand the syntax mentioned in VBA Help?

I'm trying to use send keys at the moment and VBA help says as an example

to
press Alt-F-X

Application.SendKeys("%fx")


So when I try and use Alt-F4 to exit WinAmp I type the code:

C:\Program Files\Winamp\winamp.exe.SendKeys("%{f4}")


and the moment I move to another line it comes up with the error message:
"Compile error: Expected: line number or statement or end of statement"

and
it highlights the first "backslash \".

Judging from other code experts on this site have taught me, I would have
guessed "speach marks" should go around the path to the application, but

that
doesn't work and VBA help doesn't suggest it.

Thanks in advance

Phil





All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com