1

I am trying to run Rscript from Excel VBA and I receive the following error. I tried different things but just cannot make it work. Could someone please help?

Function Run_R_Script(sRApplicationPath As String, _
                        sRFilePath As String, _
                        Optional iStyle As Integer = 1, _
                        Optional bWaitTillComplete As Boolean = True) As Integer

    Dim sPath As String
    Dim shell As Object

    'Define shell object
    Set shell = VBA.CreateObject("WScript.Shell")

    'Wrap the R path with double quotations
    sPath = """" & sRApplicationPath & """"
    sPath = sPath & " "
    sPath = sPath & sRFilePath

    Run_R_Script = shell.Run(sPath, iStyle, bWaitTillComplete)
End Function
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
iamGV
  • 11
  • 1
  • It is easy to give solutions or ideas only when you show the error code. – Sang won kim Apr 26 '19 at 04:29
  • What have you tried? Are you using System Environment Variables to call Rscript? If such try using the entire path to Rscript, something like "C:\Program files\R\R-3.5.2\bin\x64\Rscript.exe". Try executing Excel in Administrative mode and see if the problem persists. Being specific helps answering your question, while open questions are almost impossible to answer. – Oliver Apr 26 '19 at 05:12

0 Answers0