ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro attached to Menu Command Button (https://www.excelbanter.com/excel-programming/413492-macro-attached-menu-command-button.html)

steven

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,

Steven



FSt1

Macro attached to Menu Command Button
 
hi
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.

Regards
FSt1

"Steven" wrote:

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,

Steven



steven

Macro attached to Menu Command Button
 
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.

Thanks,

Steven

"FSt1" wrote:

hi
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.

Regards
FSt1

"Steven" wrote:

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,

Steven




All times are GMT +1. The time now is 08:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com