Message for Bob Phillips

D

donwb

Hi Bob

Hi Bob

Workbook specific custom toolbars

Not sure if you were able to pick up my response to your last message.
Here it is:-

By way of a simple test, I created two WBs, Test1 & Test2.
Test1 has the code:-
Sub MyClose()
ThisWorkbook.Close SaveChanges:=False
End Sub
located in "ThisWorkbook"

Test2 has the code:-
Private Sub Workbook_Activate()
MsgBox "I'm activated"
End Sub
also located in "ThisWorkbook"

With both WBs open, if I run the code in Test1 to close it
an error message appears:-
"Application-defined or object-defined error",
WB1 closes, but the MsgBox never appears.

However, if I close WB1 using instead the menu bar user interface
File/Close,
Activate is triggered and the MsgBox appears.

I want to do the closing programmatically so I'm still stuck.
donwb
 
G

Gary''s Student

The order of actions is important:

With two workbooks open, test1.xls and test2.xls

In test1.xls:

Private Sub Workbook_Activate()
MsgBox ("in test1")
End Sub

In test2.xls:

Sub MyClose()
Windows("test1.xls").Activate
ThisWorkbook.Saved = True
ThisWorkbook.Close
End Sub

Say test2 is the active workbook. If MyClose is run:

1. test1 will be activated
2. test2 will be closed without saving
3. test1 will display the message
 
D

donwb

Thanks Garry's Student.
This worked up to a point.
I put your code for test1.xls in "ThisWorkbook"
and that for test2.xls in its own module.
This still produced the same error message after clearing the MsgBox.
However putting test2.xls into "ThisWorkbook" instead of a module,
and changing the code from "Windows("test1.xls").Activate"
to Workbooks("test1.xls").Activate worked fine.
Many thanks
donwb
 

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

Similar Threads


Top