Reputation: 1
I have an R file that executes some code and then writes the outcomes to an Excel file. I want to create a button in Excel to execute this R file. Creating a button in a separate Excel file works, but if the button is in the file to which R writes, it doesn't work, because R only writes to files that aren't currently used.
Therefore, if I could add a line in R that closes the Excel file, then the writing to the closed Excel file will not be a problem. (I also want to open the file again afterwards)
I hope someone can help!
Upvotes: 0
Views: 3144
Reputation: 1954
You can send system commands using the R command system()
I just tested out the following with Excel open on a windows machine, which worked:
system("taskkill /IM Excel.exe")
Referenced this answer for how to close programs: https://superuser.com/questions/727724/close-programs-from-the-command-line-windows
Upvotes: 2