View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Message for Bob Phillips

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
--
Gary''s Student - gsnu200802


"donwb" wrote:

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