2016-12-28 56 views
0

我有一個編輯R腳本的宏。 是R腳本然後應該由下面的VBA被調用:在VBA中運行R腳本錯誤目錄

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) 

上述代碼是從this question

當我執行宏,但是,r命令行給了我一個錯誤,指出:

'\\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" 

腳本存儲我的Excel工作簿是在文件夾中

誰能幫助我出去找我的問題?

+0

,如果你嘗試運行** [R腳本會發生什麼**通過更換用'shell.Run路徑,1,TRUE;最後一行?它工作嗎? –

+0

不幸的是,不 - 我得到同樣的錯誤。 – reggie86

+0

這個文件存放在哪裏R RAM Cluster Script.R? – cyboashu

回答

1

試試這個:

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 
+0

將批處理參數的r.exe更改爲rscript.exe。 – PhilC

+0

嘗試在參數中添加R文件'c:\ YOUR DIR \ R RAM ...'的路徑。該錯誤是由於rscript未找到腳本。 – PhilC

+0

再試一次? c:/ mypath備註在斜線方向上更改 – PhilC

0

我建議嘗試使用PowerShell作爲包裝您的腳本,因爲它不支持UNC路徑。所以,這樣的事情應該工作:

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'}" 
+0

這確實有助於解決目錄問題,但由於「程序」和「文件」之間的空間,它正在尋找名爲'C :\ Program' – reggie86

+0

啊,我會修復我的答案,然後 – KySoto

+0

現在我收到PowerShell的意外令牌錯誤。 它說: – reggie86