Error Handling

  • Thread starter Thread starter Peter Fossey
  • Start date Start date
P

Peter Fossey

Good morning all!

I have a very large automatically run script. Sometimes,
portions of this go wrong. Instead of just resuming, I'd
like to log all the errors to a text file.

Is this possible? If so, how?!

Thanks for your time,
Pete
 
Pete,

Somewhere at the beginning of your code, specify and open the log file:

Open "C:\MyFolder\LogFile.txt" for Output as #1
Note: this will overwrite the previous file every time the macro is run; you
could use date/time as part of the file name to create
a new file each time, or use "Open ... for Append as #1" instead, to add to
the file instead of replacing it. In the latter case, it would be a good
idea to start with a blank line and then one with the start date/time:
Print #1,
Print #1, "Macro started " & Now()

Then each time you want something logged, use a print expression:
Print #1, "text to be logged text..."

At the end of your code, be sure to close the file:

Close #1

HTH,
Nikos
 
Back
Top