Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending An Email In Excel Programmatically W/O Sending An Object [email protected] Excel Programming 8 December 1st 08 09:35 PM
Sendkeys, sending variable Brent Excel Programming 1 May 17th 07 03:25 AM
Always Sendkeys... Duncan[_5_] Excel Programming 0 May 4th 06 09:10 AM
SendKeys [email protected] Excel Programming 1 July 25th 05 06:05 PM
Sendkeys GB[_3_] Excel Programming 0 September 16th 03 10:39 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"