Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
Hi all
W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
CMD.EXE is a DOS window and will not work with send key. You have few choices 1) Put your commands into a ".BAT" file and execute the bat file from the shell command shell("CMD.EXE c:\temp\mybat.bat") 2) Open a explorer window hndl = Shell("c:\windows\explorer.exe") 3) Open the application directly using the shell command hndl = shell("C:\Program Files\Microsoft Office\OFFICE11\excel.exe") -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=145546 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
This worked for me -
Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) Application.OnTime Now + TimeSerial(0, 0, 1), "typeKeys" End Sub Sub typeKeys() SendKeys "ipconfig /all {ENTER}", True ' MsgBox "done" End Sub Note SendKeys might not work at all in Vista. Shame there doesn't seem to be a way to write the report to file. If so could close the dos window and read the report back into VBA. Regards, Peter T "AltaEgo" <Somewhere@NotHere wrote in message ... Hi all W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
Thank you. I now have it working using 'Sleep 500' (which is the same basic
idea). I guess the 'problem' stems from SendKeys commands not being buffered by the command window. -- Steve "Peter T" <peter_t@discussions wrote in message ... This worked for me - Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) Application.OnTime Now + TimeSerial(0, 0, 1), "typeKeys" End Sub Sub typeKeys() SendKeys "ipconfig /all {ENTER}", True ' MsgBox "done" End Sub Note SendKeys might not work at all in Vista. Shame there doesn't seem to be a way to write the report to file. If so could close the dos window and read the report back into VBA. Regards, Peter T "AltaEgo" <Somewhere@NotHere wrote in message ... Hi all W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
Maybe you can use something like this:
dim myFileName as string dim myParms as string myfilename = "ipconfig" myparms = "/all" Shell Environ("comspec") _ & " /k " & Chr(34) & myFileName & Chr(34) & " " & myparms, vbNormalFocus Use /c says to close that (hidden!) window when it's done. The /k to see the command window (/k = keep open) (nice for testing). I used /k and NormalFocus to test. I'd use /c and vbHide when I was done testing. But I would think you'd want to open the output of that ipconfig command. Maybe something like: Dim myFileName As String Dim myParms As String myFileName = "ipconfig" myParms = "/all C:\myfile.txt" Shell Environ("comspec") _ & " /c " & Chr(34) & myFileName & Chr(34) & " " & myParms, vbHide Would work ok. AltaEgo wrote: Hi all W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
Excellent !
Regards, Peter T "Dave Peterson" wrote in message ... Maybe you can use something like this: dim myFileName as string dim myParms as string myfilename = "ipconfig" myparms = "/all" Shell Environ("comspec") _ & " /k " & Chr(34) & myFileName & Chr(34) & " " & myparms, vbNormalFocus Use /c says to close that (hidden!) window when it's done. The /k to see the command window (/k = keep open) (nice for testing). I used /k and NormalFocus to test. I'd use /c and vbHide when I was done testing. But I would think you'd want to open the output of that ipconfig command. Maybe something like: Dim myFileName As String Dim myParms As String myFileName = "ipconfig" myParms = "/all C:\myfile.txt" Shell Environ("comspec") _ & " /c " & Chr(34) & myFileName & Chr(34) & " " & myParms, vbHide Would work ok. AltaEgo wrote: Hi all W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve -- Dave Peterson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
SendKeys not sending to Cmd.exe
Thank you. I have a Q&D system working with shell (cmd) but this looks very
interesting. Hidden is a major bonus. I will revisit the problem using your suggestion below. -- Steve "Dave Peterson" wrote in message ... Maybe you can use something like this: dim myFileName as string dim myParms as string myfilename = "ipconfig" myparms = "/all" Shell Environ("comspec") _ & " /k " & Chr(34) & myFileName & Chr(34) & " " & myparms, vbNormalFocus Use /c says to close that (hidden!) window when it's done. The /k to see the command window (/k = keep open) (nice for testing). I used /k and NormalFocus to test. I'd use /c and vbHide when I was done testing. But I would think you'd want to open the output of that ipconfig command. Maybe something like: Dim myFileName As String Dim myParms As String myFileName = "ipconfig" myParms = "/all C:\myfile.txt" Shell Environ("comspec") _ & " /c " & Chr(34) & myFileName & Chr(34) & " " & myParms, vbHide Would work ok. AltaEgo wrote: Hi all W7 XL2007 (same problem on XP. 2003) Cannot use Cscript or Wscript. I need to send some commands to a command window. Tested this code (and variations). The Cmd window receives no keystrokes but the Msgbox pops up. Sub test() Dim ReturnValue ReturnValue = Shell("CMD.EXE", 5) 'AppActivate ReturnValue 'will err when uncommented SendKeys "ipconfig /all {ENTER}", True MsgBox "done" End Sub -- Steve -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sending An Email In Excel Programmatically W/O Sending An Object | Excel Programming | |||
Sendkeys, sending variable | Excel Programming | |||
Always Sendkeys... | Excel Programming | |||
SendKeys | Excel Programming | |||
Sendkeys | Excel Programming |