0

I am using some code I took from here; Run R function in VBA macro

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 

I'm also using the same code itself but getting the error: Run-time error 429 mentioning "ActiveX component can't create object". Please help me with this issue. Thank You!

Matt
  • 74,352
  • 26
  • 153
  • 180

1 Answers1

0

You should probably take a look at this.

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

Also, consider doing it this way.

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

Look closely at the path...

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

ASH
  • 20,759
  • 19
  • 87
  • 200