(Solved) – Run R script from VBA

(solved)-–-run-r-script-from-vba

I have tried several examples found on forums to run my R script from VBA, but it doesn’t work. The R script works well alone. Here is the code I ran:

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 C:UsersDocumentsCode.R"
errorCode = shell.Run(path, style, waitTillComplete)

End Sub

I’m getting an error message saying that running object “IWshShell3” failed. Is there anything special to write on the R code prior to running this macro? Shall I load a package, or load the files in a specific folder?

Leave a Reply

Your email address will not be published. Required fields are marked *