This means that when the second workbook is closed, the If statement will skip over the body of the AutoClose macro. If you open the second workbook from your first workbook, then the code in your first workbook can call the DisableAutoClose macro in the second workbook, thereby setting the AutoCloseDisabled flag to True. (Boolean variables default to False when they are declared.) Since the DisableAutoClose procedure is never run in the workbook, the If statement in the AutoClose macro allows the actual body of the macro to be executed. The idea is that when the second workbook is opened normally, the AutoCloseDisabled variable will be automatically set to False. Next, modify the AutoClose macro so that its body is enclosed within an If statement, as shown here: Note that the declaration statement for the AutoCloseDisabled variable is outside of any procedure, which means that it will be global in scope and accessible within all the procedures. To do this, in the second workbook at the top of the module pages add the following code: This flag could test to see if the first workbook is open, and if it is, not run the main code in the AutoClose macro. You can (and should) then set the EnableEvents property to True so that events can later continue.Īnother workaround is to set some sort of "flag" in the AutoClose macro of the second workbook. The first involves modifying your code that closes the second workbook, in this manner:īy setting the EnableEvents property to False, the event that is going to happen (closing the workbook) will not trigger the AutoClose macro. There are a couple of workarounds, however. (If you are opening it manually, you can obviously hold down the Shift key as the workbook opens, but that doesn't help your macro-it has no fingers to hold down that key!) There is no way to disable the macros in the second workbook when opening it under macro control. He is looking for a way to open the second workbook, under the control of the macro in the first workbook, without enabling the macros in the second workbook. He would like for the macro to open a second workbook that has an AutoClose macro in it, but he doesn't want it to run when the second workbook is closed. Bob is processing information in a workbook by using a macro.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |