如果您可以使用MS WinSock控件(另请参阅在VBA中使用winsock)
更多资源:
如果没有,您可以使用cmd.exe,SendKeys
也许:
免责声明:我从下面的第二个链接复制了下面的代码,并针对 VBA 稍微修改了它。
sub telNETScript()
On Error Resume Next
Dim WshShell as object
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 1000
'Send commands to the window as needed - IP and commands need to be customized
'Step 1 - Telnet to remote IP'
WshShell.SendKeys "telnet xx.xx.xx.73 9999"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 2 - Issue Commands with pauses'
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys "5"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
'Step 3 - Exit Command Window
WshShell.SendKeys "exit"
WshShell.SendKeys ("{Enter}")
WScript.Quit
end sub
Run Code Online (Sandbox Code Playgroud)
SendKeys
这不是最好或最可靠的解决方案,但这是我 12 年前在上一份工作中这样做时所能找到的。
更多信息:
Telnet 和 Excel - Microsoft.excel.programming