在Excel VBA中运行RScript时出错 [英] Error running RScript in Excel VBA

查看:305
本文介绍了在Excel VBA中运行RScript时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过几个解决方案搜索了同样的问题,但是我的代码仍然不起作用。确保我的文件路径中没有空格,但仍然有三重引用可以肯定。我得到运行宏的对象IWshShell3失败的方法运行错误。我可以在这里丢失什么?

I've searched through several solutions to this same problem, but my code still doesn't work. Made sure to not have spaces in my file path, and still have it triple quoted to be sure. I get the "Method 'Run' of object 'IWshShell3' failed" error from running the macro. What could I be missing here?

代码:

Sub RunRscript()
    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 = "RScript ""G:\structureshouston\Kocian\hello.R"""
    errorCode = shell.Run(path, style, waitTillComplete)
End Sub


推荐答案

我相信你的报价水平是不正确的。 RScript应该是引号,脚本的文件名不应该是。此外,我想确保我在通话中包含完整路径名。尝试:

I believe your level of quotes is incorrect. The RScript should be in quotes while the filename for the script shouldn't be. Also, I like to make sure I include the full path names in the call. Try:

path = """C:\Program Files\R\R-3.2.4revised\bin\RScript"" G:\structureshouston\Kocian\hello.R"

你可以需要根据您安装的版本更新RScript的路径。

You may need to update the path to RScript depending on the version you have installed.

这篇关于在Excel VBA中运行RScript时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆