Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如果处理多个文件,Shell代码不会在XP环境中运行_Excel_Vba_Wsh_Windows Scripting - Fatal编程技术网

Excel 如果处理多个文件,Shell代码不会在XP环境中运行

Excel 如果处理多个文件,Shell代码不会在XP环境中运行,excel,vba,wsh,windows-scripting,Excel,Vba,Wsh,Windows Scripting,我编写的这段VBA代码在Windows7中运行,但在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,

我编写的这段VBA代码在Windows7中运行,但在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,当脚本发生问题时,代码将流向该GOTO。但当我在XP环境中运行它时,WinXPMode部分和上面的部分并行运行,我认为它冻结了程序流

我有两个问题

有没有办法升级代码,使之在Windows7和XP中都能工作,这样我就不用担心环境了。 有没有办法检查代码或系统有什么问题?
我发现,当我为几个文件运行.jar(10或20个文件名)时,它不会出现任何问题。之后,我尝试了很多文件,比如100个文件名。然后它向我显示了一个错误,无法输出文件无法写入文件,这在Windows 7中不显示。

如果命令为notepad.exe change windowStyle=1,它是否工作?通常这应该是一个子函数,函数的目的是在最后返回一些东西。该命令的内容是什么?@PatricK命令类似于java-jarjcompressor.jar&fileName&-o&fileName&-charset utf8notepad.exe。我之所以使用wsh是因为我多次调用这个jar文件,我需要将它与程序同步。现在看看哪一行给出了错误,或者代码实际上冻结了哪一行OK,听起来XP没有环境变量来启动java.exe?在XP中,启动命令提示符并键入java并按Enter键,它是否显示用法?如果没有,那么它将丢失java.exe的路径,因此不会执行任何操作。