Hi,
I am having trouble with the 3rd line of code from below:
book <- ex$workbooks()$Open(file)
in which the ex$workbooks() is resulting in an error as follows:
Error in .COM(x, name, ...) :
Cannot locate 0 name(s) workbooks in COM object (status = -2147418111)
Strangely, this was not an issue yesterday, but with no change to the code it now does not work today. The file is irrelevant for this step as the error occurs before it gets to the Open(file) part. I am not sure how to go about this, my R version is 4.2.2. Any help would be appreciated, thanks!
file <- getAbsolutePath("myfile.xlsx")) # absolute path to Excel file
ex <- COMCreate("Excel.Application") # create COM object
book <- ex$workbooks()$Open(file) # open Excel file
excel <- book$Worksheets()excel$Select()ex[["ActiveSheet"]]$ExportAsFixedFormat(Type=0, Filename=paste0(getwd(), "myfile.pdf"), IgnorePrintAreas=FALSE) # export as pdf
ex[["ActiveWorkbook"]]$Save() # save workbook
ex$Quit() # close Excel`
Hi, I am having trouble with the 3rd line of code from below:
book <- ex$workbooks()$Open(file)
in which the ex$workbooks() is resulting in an error as follows:Error in .COM(x, name, ...) : Cannot locate 0 name(s) workbooks in COM object (status = -2147418111)
Strangely, this was not an issue yesterday, but with no change to the code it now does not work today. The file is irrelevant for this step as the error occurs before it gets to the Open(file) part. I am not sure how to go about this, my R version is 4.2.2. Any help would be appreciated, thanks!
file <- getAbsolutePath("myfile.xlsx"))
# absolute path to Excel fileex <- COMCreate("Excel.Application")
# create COM objectbook <- ex$workbooks()$Open(file)
# open Excel fileexcel <- book$Worksheets()
excel$Select()
ex[["ActiveSheet"]]$ExportAsFixedFormat(Type=0, Filename=paste0(getwd(), "myfile.pdf"), IgnorePrintAreas=FALSE)
# export as pdfex[["ActiveWorkbook"]]$Save()
# save workbookex$Quit()
# close Excel`