I am trying to write a batch file that will open two Excel documents and close them without losing data.
I need this because the first document is automatically downloaded from the Internet every day and contains raw data. The second document uses these data from the first document and arranges them in a more intelligible way. In order to update the second document, the first one needs to be open. The second document contains a VBA code that will save it on closing (without any prompt/notification per settings).
I am not a programmer, but with the help of Google I managed to write the following code:
@echo off
start excel "c:\data.csv"
timeout 5
start excel "c:\formatted_data.xlsm"
timeout 5
taskkill /F /IM excel.exe
exit
It all works fine apart from closing the document. It kills the process forcefully and the VBA code contained in c:\formatted_data.xlsm
that's supposed to save the document on closing doesn't work then.
Is there any "gentler" way of closing the document using a batch file, that works in the same way as if I pressed the cross in the upper right corner, so that the updated document will be saved on closing?
Thank you in advance for your help.