1

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?

1
  • into your auto-open macro, you can improve all error with: On Error GoTo ErrorHandler and then ErrorHandler: here you can put the code for display error message, send one mail with the error,... and then exit from excel Commented Jun 26, 2015 at 10:36

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.