VBA意外的字符在文件名称变通办法

我正在使用vba shell来运行R代码,但是我遇到了文件名的问题。 文件path中有一个反斜杠,后面跟着下划线。 我无权删除下划线。 使用此path运行代码时,会引发意外的字符错误。 如果我用不同path的文件运行代码,这不是一个更长期的解决scheme,代码将无缝地运行。

Sub RunRscript() Dim s As String Dim n As Integer Dim shell As Object Set shell = VBA.CreateObject("WScript.Shell") Dim waitTillComplete As Boolean: waitTillComplete = True Dim style As Integer: style = 1 Dim errorCode As Integer Dim path As String path = """C:\Program Files\R\R-3.2.3\bin\Rscript.exe""V:\_Our Division\R_Script.R -R & Pause " 

有没有解决方法?

这可能只是您的命令行中的间距问题。 尝试这个:

 path = """C:\Program Files\R\R-3.2.3\bin\Rscript.exe"" ""V:\_Our Division\R_Script.R"" -R & Pause " 

请注意,我将Rscript.exeR_Script.Rpath都放在引号中。 Windows应该更喜欢这两个path中有空格。