Macro attached to Menu Command Button



I assigned a macro to a Menu Command Button in File1 that opens another file
(File2) and then the File1 macro continues and calls a macro in File2 with
Application.Run "..." and then after the macro in File2 has run the last line
of code in the macro of File1 is to close File1,
Windows("File1.xls").Close(0). But I get an "Appliation Defined Error!"

Note: I dont want to go directly to File2 from the Command Button. I want
to use File1's macro assigned to the Command Button.

How do I do this and not get the error?

Thank you,



you don't.
file1 macro is the master macro that call the other macro in file 2. the
master macro ends when it hits it's end sub not the end sub in macro 2 in
file 2. so you are trying to close a file that still has a macro running.
opps. error. sorry no way around that. macro 1 must complete before closeing.



Thank you for the response. It is unusual to me. If it is a code running in
an already opened file and I assign a macro to a rectangle object for example
it works fine to run the code and close the file, but if it is assigned
directly from a command button on the menu then it errors.



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