这里's a method which doesn' t需要一个VBscript包装器 . 您需要安装 RDCOMClient 包
library(RDCOMClient)
# Open a specific workbook in Excel:
xlApp <- COMCreate("Excel.Application")
xlWbk <- xlApp$Workbooks()$Open("C:\\Temp\\macro_template.xlsm")
# this line of code might be necessary if you want to see your spreadsheet:
xlApp[['Visible']] <- TRUE
# Run the macro called "MyMacro":
xlApp$Run("MyMacro")
# Close the workbook and quit the app:
xlWbk$Close(FALSE)
xlApp$Quit()
# Release resources:
rm(xlWbk, xlApp)
gc()
2 回答
编写一个调用VBA的VBscript包装器 . 见Way to run Excel macros from command line or batch file?
通过R的system或shell函数运行VBscript .
这里's a method which doesn' t需要一个VBscript包装器 . 您需要安装
RDCOMClient
包