t1hodges
MIS
- May 8, 2003
- 54
is it possible to call the cmd prompt with VBA, run a command like IPCONFIG /ALL, copy the results from the window and paste the results into a spreadsheet.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub testIPConfig()
Dim objShell As Object
Dim intFile As Integer, intRow As Integer, intColumn As Integer
Dim strCurrentLine As String
'Shell "cmd.exe" "ipconfig/all > ipcfg.txt"
Set objShell = CreateObject("Wscript.Shell")
objShell.Run ("%comspec% /c ipconfig /all > C:\ipcfg.txt")
Set objShell = Nothing
'Wait 3 seconds for file to appear
Application.Wait Now + 0.00003
'Get file and worksheet information
intFile = FreeFile
intRow = ActiveCell.Row
intColumn = ActiveCell.Column
Open "C:\ipcfg.txt" For Input As #intFile
'Read the file
Do
Line Input #intFile, strCurrentLine
Select Case Len(strCurrentLine)
Case 0
'Line is blank
intRow = intRow - 1
Case Is < 43
Cells(intRow, intColumn) = strCurrentLine
Case Else
Cells(intRow, intColumn + 1) = Mid(strCurrentLine, 8, 26)
Cells(intRow, intColumn + 2) = Mid(strCurrentLine, 45)
End Select
intRow = intRow + 1
Loop Until EOF(intFile)
Close #intFile
End Sub