从R调用VBA宏

时间:2017-09-22 14:53:06

标签: r vba

我正在尝试从R调用一个宏,我已经按照this的问题回答了问题,但我发现了一个错误:

<checkErrorInfo> 80020009 
Error: Exception occurred.

我的代码如下:

library(RDCOMClient)

# Open a specific workbook in Excel:
xlApp <- COMCreate("Excel.Application")
xlWbk <- xlApp$Workbooks()$Open("Y:\\macroR.xlsm")

# this line of code might be necessary if you want to see your spreadsheet:
xlApp[['Visible']] <- FALSE 

# Run the macro called "MyMacro":
xlApp$Run("LoopAllExcelFilesInFolder")

# Close the workbook and quit the app:
xlWbk$Close(FALSE)
xlApp$Quit()

# Release resources:
rm(xlWbk, xlApp)

该宏应该删除用户选择的文件夹中包含的所有工作簿中的所有工作表中的所有删除单元格。如果相关,我可以共享代码。

0 个答案:

没有答案