output standardization to to cell

P

PhrozenRoad

Hey guys is there a way to output the results of this macro to a cell
like

if ("cmd /c C:\WINDOWS\system32\ping.exe -t " & Replace(C.Value, "connected
", ""), vbMaximizedFocus) = "Reply from" then (0,1).Value="Pinged!"

if ("cmd /c C:\WINDOWS\system32\ping.exe -t " & Replace(C.Value, "connected
", ""), vbMaximizedFocus) = "Request timed out"C.Offset(0,1).Value="Failed!"




**********************************************************
Sub AddPingString()
Dim TheRange As Range, iMsgBox As Integer
Dim retval As Integer

If TypeName(Selection) = "Range" Then

'get the range of cells to modify
Set TheRange = Application.Selection
'loop through the cells in the range object
For Each C In TheRange.Cells
'use data from selected cell if not hidden
If C.EntireRow.Hidden = False And C.Value <> "" Then
'adds Value to cell to show script attempt has been made
C.Offset(0,1).Value="Pinged!"
End If
'open cmd prompt and start conn, replace cell value
"connected " with "" leaving only system name
retval = Shell("cmd /c C:\WINDOWS\system32\ping.exe
-t " & Replace(C.Value, "connected ", ""), vbMaximizedFocus)
End If
Next

Else
iMsgBox = MsgBox("Select some cells.", vbInformation, "Error")
End If
 
P

PhrozenRoad

I worked through it last night and this was what i came up with
I'm going to use this as a model for the other commands

******************************************
Public Sub Test_Ping()
Dim TheRange As Range, iMsgBox As Integer
Dim retval As Integer
Dim STRtest As String
Dim STRping As String
Dim ws, execCode1 As Variant

Set ws = CreateObject("WScript.Shell")

If TypeName(Selection) = "Range" Then

'get the range of cells to modify
Set TheRange = Application.Selection
'loop through the cells in the range object
For Each C In TheRange.Cells
'use data from selected cell if not hidden
If C.EntireRow.Hidden = False And C.Value <> "" Then

STRping = "cmd /c c:\windows\system32\ping.exe -n 1 " &
C.Value & " | FIND ""Reply"" | c:\quickaccess\cut -f 1 -d " & Chr(34) &
Chr(32) & Chr(34)

Set execCode1 = ws.Exec(STRping)
STRtest = execCode1.StdOut.ReadAll
STRtest = Replace(STRtest, Chr(13), "")
STRtest = Replace(STRtest, Chr(10), "")
STRtest = Replace(STRtest, Chr(20), "")

If STRtest = "Reply" Then
C.Offset(0, 1).Value = "Pings!"
Else
C.Offset(0, 1).Value = "Failed"
End If
End If

Next

Else
iMsgBox = MsgBox("Select some cells.", vbInformation, "Error")
End If
End Sub
 
P

PhrozenRoad

for reference cut.exe is a unix tool

C:\quickaccess>cut --help
cut: Unknown option --
Usage: cut -b list [-n] [file ...]
cut -c list [file ...]
cut -f list [-d char] [-s] [file ...]

I think i just solved my own question. how do i mark this thing as solved.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top