How to stop macro that is calling another one from the macro being called?

R

Robert

Hi all,

I have two macros - macro1 and macro2 - they are two independent macros
place in two different DOT files.
macro1 opens first file placed in a specified folder then calls macro2 which
performs some checks on the open file and finally closes the file (the same
does with all other files in the folder). macro1 interacts with the user via
the modal user form. macro2 has no UI. The problem is that if some runtime
error occurs in the macro2, it finishes immediately (as expected), but
because it is called from the loop placed in macro1, as soon as another file
is opened, macro1 calls macro2 again and again even though once the bug
occured in macro2, the files processing must end. (The error occurs when the
user leaves the modal user form (contained in macro1) displayed (the user is
advised to hide it by checking the appropriate check box, but you know...).
In such a case when macro2 tries to show another form (modeless in this
case) I get the error saying that a modeless form cannot be displayed while
a modal form is displayed.

So I tried to hide modal user form by calling ShowWindow API (I do not know
how to hide the user form from another macro placed in a different DOT file
so I used API). It did not work. It disappeared from the screen but the same
error kept appearing. Does ShowWindow API do different job as
UserForm1.Hide? (Besides, I cannot use exact module names, form names etc.
because I do not know if the user uses my macro1 for batch processing or
some other one.)

I used one or two more approaches, but without success. I also tried to
present the user with the error msg but had the same problem - the error msg
either kept showing each time a file was opened or never :(

For the time being it works the way that the macro2 is called as many times
as the total number of the files to process, but it finishes immediately
without doing anything. No bug appears, however the user has to wait pretty
long time to find out he waited uselessly :)

What I'd like to know is how to tell macro1 from macro2 that it must end
immediately. I tried several things but it either did not work at all
(generated error) or worked incorrectly (no error, but did not work as
expected).

Thank you very much.
Regards,
Robert
 
R

Robert

Hi,

in addition to my previous mail. Is it possible to find out from macro2's
code the name of the macro1's function from which macro2 was called? Or even
better the project name, module name and function name? This way I would
probably be able to solve the problem. I use Word 2003.


Thank you.
Regards,
Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top