很长时间以来,我一直在成功使用vba在Excel 2010和Windows 7中运行我的r脚本。然后,我不得不使用另一台安装了Excel 2013和Windows 8的计算机。它给我以下错误:
对象“ IWshShell3”的方法“运行”失败
这是在Excel 2010中运行的代码:
Dim shell As Object
Set shell = VBA.CreateObject("WScript.Shell")
Dim waitTillComplete As Boolean: waitTillComplete = True
Dim style As Integer: style = 0
Dim errorCode As Integer
Dim var1 As String
Dim PATH As String
var1 = Replace(Replace(ThisWorkbook.PATH, "\", "/") & "/", " ", "_z9z_")
PATH = "C:\PROGRA~1\R_App\bin\x64\RScript """ & "C:\JF\Code A\dvlp.R"" " & var1 & " " & 2500
errorCode = shell.Run(PATH, style, waitTillComplete)
相同的代码无法在我提到的另一台计算机上运行。
我在stackoverflow中经历了其他问题,指出了相同的问题,但是那里的解决方案并没有帮助我。例如,我已经使用双引号,并且我尝试了将其删除。
有什么想法吗?
考虑更干净的命令行Rscript
调用,它可以处理名称中的空格,这可能是这里的问题。下面还集成了适当的错误处理。