cmd /k表示 执行完后面吵陆的命态碰滚令时,窗帆余口保留,/c表示窗口关闭
Dim pid As Longpid = Shell("cmd.exe /C Ping " &Text1.Text &" >c:\r.txt", vbHide)
' 提示
Text2.Text = "正在执行纯轮举Ping " &Text1.Text &" ..."
'等待Shell执行结束
Dim hProc As Long
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid)
Dim ExitCode As Long
Do
Call GetExitCodeProcess(hProc, ExitCode)
DoEvents
Loop While ExitCode = STILL_ALIVE
'清空,准备显示桐睁结果
Text2.Text = ""
'打开 C:\r.txt文件
Open "c:\r.txt" For Input As #1
Dim strLine As String
Do Until EOF(1)
Line Input #1, strLine
'显示执行结果
Text2.Text = Text2.Text &strLine &vbNewLine
Loop
'关闭文件
Close #1
'删除做碧C:\r.txt
On Error Resume Next
Kill "c:\r.txt"
如果你是直接在VBA中输入CMD命令打开“C:\a a.txt”,可盯哗以这样:Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "%Comspec% /c " &"""" &"C:\a a.txt" &""""
如果是在VBA中打开一个BAT文件,BAT文件中是打开“C:\a a.txt”,那么VBA中命令为:
Set wshShell = CreateObject("码乎WScript.Shell")
wshShell.Run "C:\open.bat",0
而“C:\open.bat”中迟则悉的内容为:
start "c:\a a.txt"(或直接写:"c:\a a.txt",注意加引号)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)