2017-05-31 33 views
0

我正在使用一些代碼, Run R function in VBA macro在VBA中使用Shell命令在E​​xcel中運行R腳本

Sub RunRscript() 
'runs an external R code through Shell 
'The location of the RScript is 'C:/Users/abhishek.b.jai/Downloads/data' 
'The script name is 'testcode.R' 
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:/Users/abhishek.b.jai/Downloads/data/testcode.r" 
errorCode = shell.Run(path, style, waitTillComplete) 
End Sub 

我還使用相同的代碼本身,但得到的錯誤:運行時錯誤429提「ActiveX組件不能創建對象」。 請幫我解決這個問題。 謝謝!

+0

你在Mac上運行嗎? –

+0

檢查您的參考? – Lowpar

+0

檢查此答案:https://stackoverflow.com/questions/18306362/run-r-script-from-command-line –

回答

0

你應該看看這個。

http://rcom.univie.ac.at/download.html

另外,還要考慮做這種方式。

Sub RunRscript() 
'runs an external R code through Shell 
'The location of the RScript is 'C:\R_code' 
'The script name is 'hello.R' 

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 C:\R_code\hello.R" 
errorCode = shell.Run(path, style, waitTillComplete) 
End Sub 

仔細查看路徑...

https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/

相關問題