Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to execute a command in VBA

I have a spreadsheet with some ip addresses in it that I would link to issue a "ping" command for, parse the results and put the results in a different worksheet. I am able to use WScript to execute the command and get the results back in variable but there is a very annoying window that pops up and then disappears. I assume that it is the window that comes up when you run "cmd" from the Windows start button.

Is there a way to not have the window come up. If I use run I can not get the output into the variable.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default How to execute a command in VBA

Hi Dirk,

Am Thu, 11 Apr 2013 10:48:41 -0700 (PDT) schrieb Dirk:

I have a spreadsheet with some ip addresses in it that I would link to issue a "ping" command for, parse the results and put the results in a different worksheet. I am able to use WScript to execute the command and get the results back in variable but there is a very annoying window that pops up and then disappears. I assume that it is the window that comes up when you run "cmd" from the Windows start button.


please have a look:
http://social.technet.microsoft.com/...-fd4be559f50f/


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to execute a command in VBA

This is the code that I have and that works. If I use the "run" option I get a type mismatch error.

Option Explicit
Sub test_function()

Dim var_1 As String
Dim var_2 As String

var_1 = "192.168.10.1"
var_2 = get_info(var_1)
Debug.Print var_2

End Sub

Function get_info(ip As String) As String

Dim obj_wsh
Dim obj_run
Dim var_cmd
Dim var_result As String
Dim var_lines() As String

Set obj_wsh = CreateObject("WScript.Shell")
var_cmd = "ping -n 4 -w 30 " & ip

' Set obj_run = obj_wsh.Run("%ComSpec% /c " & var_cmd & "| nul 2&1", 0, True)
Set obj_run = obj_wsh.exec("%ComSpec% /c " & var_cmd)
var_result = obj_run.StdOut.ReadAll
var_lines = Split(var_result, vbCrLf)
get_info = var_lines(1)

End Function
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
Execute command in Right Click through VBA Vikesh Jain Excel Programming 1 June 25th 07 12:13 PM
Execute a ping command Significent Excel Programming 10 November 22nd 05 01:26 AM
How do I execute command from button or hyperlink? rerhart Excel Discussion (Misc queries) 1 February 18th 05 09:41 PM
VBA Equivalent of ASP 'Execute' Command The Vision Thing Excel Programming 7 February 6th 05 10:59 PM
Execute a menu command with VBA? Susan[_3_] Excel Programming 2 May 1st 04 07:45 AM


All times are GMT +1. The time now is 02:43 PM.

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

About Us

"It's about Microsoft Excel"