Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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 VBA外壳“;“未找到文件”;_Vba_Shell_Excel - Fatal编程技术网

Excel VBA外壳“;“未找到文件”;

Excel VBA外壳“;“未找到文件”;,vba,shell,excel,Vba,Shell,Excel,就我个人而言,我无法让这个shell过程处理变量。我正在尝试执行POSTRESULTS6,然后它将处理csv文件。“DISPLAY”参数告诉POSTRESULTS6在处理csv时显示进度窗口 Dim MyAppID As Variant Dim stExecute As String: stExecute = """C:\Program Files (x86)\PerkinElmer\LABWORKS64\POSTRESULTS6.exe""" Dim stFile As String: stF

就我个人而言,我无法让这个shell过程处理变量。我正在尝试执行POSTRESULTS6,然后它将处理csv文件。“DISPLAY”参数告诉POSTRESULTS6在处理csv时显示进度窗口

Dim MyAppID As Variant
Dim stExecute As String: stExecute = """C:\Program Files (x86)\PerkinElmer\LABWORKS64\POSTRESULTS6.exe"""
Dim stFile As String: stFile = "INFILE:C:\PostResult6\Multi-Component_Data_Import.csv"
Dim stFull As String: stFull = "stExecute & "" "" & stFile"
MyAppID = Shell("stFull" & "" "" & DISPLAY, vbNormalFocus)
AppActivate (MyAppID)
当我在一行中键入所有内容时,该过程会按预期工作,如下所示:

MyAppID = Shell("""C:\Program Files (x86)\PerkinElmer\LABWORKS64\POSTRESULTS6.exe"" & "" "" & INFILE:C:\PostResult6\Multi-Component_Data_Import.csv" & "" "" & DISPLAY, vbNormalFocus)
我想使用变量的原因是为了缩短代码行,并可能使csv文件名的过程是动态的

我猜这与空格有关,但我不知道我的错误在哪里。我也不知道如何将长字符串的代码继续到下一行。空格下划线似乎不起作用

另外,当我的shell过程非常简单时,我不必声明MyAppID变量。随着它变得越来越复杂,我开始发现关于MyAppID未定义的错误。有人知道这是为什么吗

非常感谢您的帮助

编辑:使用变量运行代码时出现的错误是“运行时错误'53':找不到文件”


我知道分配给变量的文件路径是正确的。我在windows资源管理器中测试了它们。

例如,您的问题是:
stFull=“stExecute&”“&stFile”

在引号中有
stExecute
,这使它成为一个文本而不是一个变量

我认为这是正确的:

  Dim MyAppID As Variant
  Dim stExecute As String: stExecute = """C:\Program Files (x86)\PerkinElmer\LABWORKS64\POSTRESULTS6.exe"""
  Dim stFile As String: stFile = "INFILE:C:\PostResult6\Multi-Component_Data_Import.csv"
  Dim stFull As String: stFull = stExecute & " " & stFile
  MyAppID = Shell(stFull & " DISPLAY", vbNormalFocus)

你的语录很混乱<最后一行中的code>stFull将作为文本而不是字符串进行计算。这是我试图解决你的报价崩溃

    Dim stExecute As String: stExecute = "C:\Program Files (x86)\PerkinElmer\LABWORKS64\POSTRESULTS6.exe"
Dim stFile As String: stFile = "INFILE:C:\PostResult6\Multi-Component_Data_Import.csv"
Dim StFull As String
StFull = """" & """" & """" & stExecute & """" & """" & " & """" """" & " & stFile & """"
MyAppID = Shell(stFull & "" "" & DISPLAY, vbNormalFocus)
AppActivate (MyAppID)
输出StFull:


在Shell中使用变量的我的观点:

MyAppID as variant
Dim Program as string
Dim File as string

Program = """Your path to program"""
File = """Your path to file"""

MyAppID = Shell(Program & " " & File, vbNormalFocus)
补充意见:

  • 可以使用单引号(例如Program=“Your path to Program”),但如果文件夹名称中有空格,VBA可能无法正确编译,并且会返回错误

您的报价有问题。这就解决了报价最少的问题。非常感谢你。您是否知道如何将长字符串(如我的第二个示例)继续到下一行?空格下划线不起作用。@b您必须结束一个文字,开始另一个文字,然后使用&来连接它们。例如:
stExecute=“”C:\ProgramFiles(x86)\”&
newline
“Perkinlemer\LABWORKS64\POSTRESULTS6.exe”“”
。文本中不能有额外的空格。