I am using RDCOMClient package in R. I am able to run existing Macro in Excel Workbook from R. Is there a simple way to add Macro to Excel Workbook, when Macro is written in simple ".txt" file?
So far I have:
library(RDCOMClient)
xlApp <- COMCreate("Excel.Application")
xlWbk <- xlApp$Workbooks()$Open(normalizePath(list.files(pattern=".xlsm")[1]))
### open first xlsm file in working directory
xlApp$Run("Send") ## Run existing Macro named "Send"
can i do something like xlApp$AddMacro("myMacro.txt") to add new Macro to the workbook?
Thanks.
EDIT: I manage to add empty module and name it, but somehow I cannot add actually code to it:
mo <- xlApp$Modules()$Add()
mo[["Name"]] <- "Test"
smth like mo[["Body??"]]