1

I have a macro that edits an R script. That R script is then supposed to be called by the following VBA:

 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:\Program Files\R\R-3.3.2\bin\i386\R.exe" & """ """ & "R RAM Cluster Script.R" & """"

 errorCode = shell.Run(path, style, waitTillComplete)

The above code was from this question.

When I execute the macro, however, the R Command Line gives me an error stating:

 '\\dm\home\myaccount\*Path of my original Excel File*'
 "CMD.EXE was started with the above path as the current directory. 
  UNC Paths are not supported. Defaulting to Windows directory. 
  Argument 'R  RAM Cluster Script.R' Ignored"

The script is stored in the folder that my Excel workbook is in.

Can anyone help me out with finding my problem?

3
  • what happens if you try to run the R script by replacing the last line with shell.Run path, 1, True ? does it work ? Commented Dec 28, 2016 at 17:55
  • Unfortunately, no-- I get the same error. Commented Dec 28, 2016 at 18:03
  • where is this file stored R RAM Cluster Script.R? Commented Dec 28, 2016 at 18:12

2 Answers 2

1

Try this:

Sub test()
 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:\Program Files\R\R-3.3.1\bin\RScript.exe""" & """c:/temp/R RAM Cluster Script.R"""

 errorCode = shell.Run(path, style, waitTillComplete)

End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

Change the r.exe to rscript.exe for batch arguments.
Try adding the path to the R file 'c:\YOUR DIR\R RAM ...' in your argument. The error is due to rscript not finding the script.
One more try? c:/mypath note change in slash direction
To anyone reading, use this code that PhilC posted-- It works perfectly! Note for 32-bit R users: use RScript.exe within folder i386
0

I would suggest trying to use powershell as a wrapper for your script because it DOES support UNC paths. So, something like this should work:

path = "Powershell.exe -executionpolicy bypass -Command &{'C:\Program Files\R\R-3.3.2\bin\i386\R.exe " &  ThisWorkbook.Path & "\R RAM Cluster Script.R'}"

5 Comments

This did help get around the directory problem, but because of the space between 'Program' and 'Files', it is looking for an executable called C:\Program
ah, i'll fix my answer then
Now I have received an unexpected token error for PowerShell. It says:
thinking about it, it might be that it is not expecting there to be two strings. i'll edit again
actually i found the reason you may have a problem stackoverflow.com/questions/25246735/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.