我是vba编程的新手,我在旧论坛中找到了这个功能。 我想添加一个选项,最后关闭cmd窗口,用于学习目的。 这是cmd窗口打开的函数。运行该命令后,结果将另存为字符串。
Public Function ShellRun(sCmd As String) As String
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
ShellRun = s
End Function