Error running RScript in Excel VBA Error running RScript in Excel VBA shell shell

Error running RScript in Excel VBA


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"

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


it took a little effort to get this going, but the following worked for me.

Sub RunRscript1()    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 to R executable:  C:\Users\rshuell001\Documents\R\R-3.2.5\bin\x64\R.exe    ' path to R script:  C:\Users\rshuell001\Documents\R\Download.r    ' see more setup details here    ' http://shashiasrblog.blogspot.com/2013/10/vba-front-end-for-r.html    path = "C:\Users\rshuell001\Documents\R\R-3.2.5\bin\x64\R.exe CMD BATCH --vanilla --slave C:\Users\rshuell001\Documents\R\Download.r"    'path = """C:\Users\rshuell001\Documents\R\R-3.2.5\bin\i386"" C:\Users\rshuell001\Documents\R\Download.R"    errorCode = shell.Run(path, style, waitTillComplete)End Sub

Make sure you read about setting up the 'permissions' using the link below.

http://shashiasrblog.blogspot.com/2013/10/vba-front-end-for-r.html