user1632454
user1632454

Reputation: 51

Open Excel file from batch script and return message to batch script after closing it again

I open an Excel file from the command line, using statement like this in batch file:

start /wait excel "myWorkbook.xlsb" /e/parameters

Inside the workbook, there is an auto-open macro which does something. In case of any errors I want to close Excel and send an error message back to the batch file. How to achieve that? Is it possible to quit the application with an error code or something like this?

Upvotes: 1

Views: 497

Answers (1)

ChipsLetten
ChipsLetten

Reputation: 2953

I don't think you can return an actual errorcode from VBA but to the batch file.

As mentioned by @Fabrizio you can add error handling code to your VBA. If you want your batch file to check if Excel was successful or not, then have the VBA error handler create a text file with details of the error and have the batch file check for the existence of the file. If the file exists, then batch file can rename it. This way you will also have a record of what the error was.

Upvotes: 1

Related Questions