Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 "Gary''s Student" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Bob Phillips | Excel Programming | |||
Bob Phillips | Excel Programming | |||
To: Bob Phillips | Excel Programming | |||
Bob phillips?? | Excel Programming | |||
Bob Phillips | Excel Programming |