I am trying to run a R script from Excel using VBA. Ideally, I would use an .R (Rscript) name to invoke R and run the process, or if that won't go, then invoke Rscript.exe and execute the filename passed to it.
REXcel is no good because it requires a 32-bit version of Excel (and I am not working in 1989)
I have found what seems to be a perfect script at (http://shashiasrblog.blogspot.co.uk/2013/10/vba-front-end-for-r.html) which, after suitable localisation looks like this:
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 = "C:\Users\Charles\SkyDrive\Documents\Development\G4H\Technical evaluation templates\Graphical analysis.R"
errorCode = shell.Run(path, style, waitTillComplete)
End Sub
This fails with the message
Run Time Error '-2147024894 (80070002)': Method 'Run' of object 'IWshShell3' failed.
Which tell me exactly nothing. I have tried Googling the error message but got nothing.
I have set the PATH variable to include the directory where R and Rscript live.
I suspect it is something straightforward, but there sems to be a lack of simple ways of executing R from Excel.
Rscript.exe scriptname.R
– MrFlick