嘿伙计们,我的问题是vba脚本,我在Windows 7环境下正常运行。但它不适用于XP。
Public Function WShellRun(command As String)
Dim wShell As Object
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 0
Dim errorCode As Integer
Dim wExec, rslt As String
Set wShell = CreateObject("Wscript.Shell")
wShell.CurrentDirectory = ActiveWorkbook.Path
On Error GoTo WinXpMode
errorCode = wShell.Run(command, windowStyle, waitOnReturn)
If errorCode <> 0 Then
MsgBox "SHELL COULDN`T STARTED " & errorCode, vbCritical, "SHELL ERROR"
Exit Function
End If
Set wShell = Nothing
Exit Function
WinXpMode:
Set wExec = wShell.Exec("%ComSpec% /c " & command) ''(1) execute DOS
Do While wExec.Status = 0 ''(2) wait until response
DoEvents
Loop
'rslt = wExec.StdOut.ReadAll ''(3) show result
'MsgBox rslt
Set wExec = Nothing
Set wShell = Nothing
End Function
我认为WSH不会在xp上运行所以我写了一些GOTO部分代码会在脚本发生故障时流动。但是当我在XP环境中运行它时,WinXPMode部分和上部并行运行它冻结了程序的流程(我认为)。
所以我想问你所有专家2个问题。