Results 1 to 2 of 2
2006-03-21, 21:03 #1
- Join Date
- Jul 2004
- Sumner, Washington, USA
- Thanked 0 Times in 0 Posts
Capturing Errors or Passing Variables (Word 2003 - SP2)
I have a macro that I've written for our word processors that loops through a folder of files making the changes they have selected via a dialog box. Optionally, they can also (or instead) choose to have the loop execute a macro that they have written (which would normally be saved to their Normal.dot and not to the global template that my code is in).
Today while I was modifying the procedure, I added code to capture errors. Basically, if an error crops up during execution, the file name and error number and description are saved, and that file is closed without saving. This keeps the macro from stopping in the middle of a group of files. A compilation of these errors is collected and presented to the user at the end, so they can see which files will need manual intervention for some reason.
This was working great for me as I added a bunch of new options to their list of choices. But when I tested it with a typical macro that they might choose to run, my error handling code was ignored when the error occurred from within a macro in another project (run via "Application.Run MacroName:=strMacro" from my code, where strMacro is their macro name).
Okay, I thought. I guess I can't capture errors that happen within code from another project. So I tried wrapping their code such that it would just pass the error message back to my code. Which is when I discovered that I can't seem to share public variables between projects in Word. I tried putting the public variable in a class module, but that didn't work either.
Am I missing something? Or is there no way to do this? Is there a way to make my error handling effective within their code? Or to pass variables back and forth between projects? I can't believe I haven't run into this before. Many thanks!
2006-03-21, 21:25 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Capturing Errors or Passing Variables (Word 2003 - SP2)
A procedure (or function) called by Application.Run does not pas errors back to the calling procedure, whether it is in the same project or not.
You could pass information by setting a registry value, or by writing something to a text file, or something else that stores info outside VBA.