Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys problem
I'm having trouble with the SendKeys command in Excel 2002 (Win2k). I
am trying to send commnands to a Win2k dialogue box (Power Option Properties), but the SendKeys command "^(TAB)" does not change tabs in the dialogue box like it does when typed manually on the keyboard. (According to Excel VBA help, "^(TAB)" = Ctrl+Tab). I have tried numerous other Sendkeys commands, but none of them act like Ctrl+Tab. Does anyone know how I can change tabs in a windows dialogue box using SendKeys? Or how I can get Win2k to interpret SendKeys commands "correctly"? Failing that, does anyone know how to turn hibernate on and off using an Excel macro? Part of my simple script: Set WshShell = CreateObject("WScript.Shell") WshShell.SendKeys "^{ESC}", True 'presses the Start button Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "{DOWN}", True 'highlights a link to Power Option 'Properties Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "{ENTER}", True 'opens Power Option Properties Application.Wait Now + TimeValue("00:00:02") WshShell.SendKeys "^{TAB}", True 'problem is here, this does NOT 'switch tabs within the dialogue box! Any help greatly appreciated ... Many thanks, Rod Armour |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys problem
Hi Rod,
I have no idea why SendKeys daes not work. But I think SendKeys solution is insecure. If you wuld like to handle "LOG OFF", "REBOOT" or "SHUTDOWN", please try this code. http://www.interq.or.jp/sun/puremis/colo/code/048.htm --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys problem
Thanks for the reply Colo -- wow, that's an impressive code! However,
I finally found the problem with SendKeys. Control commands like "Tab" have to be typed in brackets (this is NOT mentioned in Excel VBA help!). So, to send Crtl+Tab requires the command SendKeys "(^{TAB})" That solved the problem. Another link gave me the answer http://www.tek-tips.com/gviewthread....707/qid/717062 These comments were also helpful: http://www.cpcug.org/user/clemenzi/t...tm#VisualBasic) So here's a simple code that will turn hibernate on and off in Win2k WITH a shortcut to "Power Options Properties" placed topmost on the Start menu: Sub HibernateOnOff() Set WshShell = CreateObject("WScript.Shell") WshShell.SendKeys "^{ESC}", True Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "{DOWN}", True Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "{ENTER}", True Application.Wait Now + TimeValue("00:00:02") WshShell.SendKeys "(^{TAB})", True 'This was the "trick"! Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "(^{TAB})", True Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "%H", True Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "%A", True Application.Wait Now + TimeValue("00:00:01") WshShell.SendKeys "(%{F4})", True End Sub It's not very elegant, but it works. I may still use your code 048 to reenter hibernatation (after re-enabling it). I'll work on the problem later today. But the sendkeys issue is resolved by bracketing the control commands. Thanks again for the help! I'll post another note here later describing the final result. Rod Colo wrote in message ... Hi Rod, I have no idea why SendKeys daes not work. But I think SendKeys solution is insecure. If you wuld like to handle "LOG OFF", "REBOOT" or "SHUTDOWN", please try this code. http://www.interq.or.jp/sun/puremis/colo/code/048.htm --- Message posted from http://www.ExcelForum.com/ |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys problem
Can you handle a Lock Computer?
"Colo" wrote in message ... Hi Rod, I have no idea why SendKeys daes not work. But I think SendKeys solution is insecure. If you wuld like to handle "LOG OFF", "REBOOT" or "SHUTDOWN", please try this code. http://www.interq.or.jp/sun/puremis/colo/code/048.htm --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SendKeys syntax problem | New Users to Excel | |||
Sendkeys | Excel Programming | |||
SendKeys and Path Problem | Excel Programming | |||
SendKeys | Excel Programming | |||
sendkeys | Excel Programming |