LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 
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:04 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"