Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Message for Bob Phillips

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   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Message for Bob Phillips

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bob Phillips Simon Lloyd[_863_] Excel Programming 2 August 14th 06 01:38 PM
Bob Phillips Tom Ogilvy Excel Programming 0 August 6th 04 03:19 PM
To: Bob Phillips Metallo[_4_] Excel Programming 3 July 14th 04 07:43 PM
Bob phillips?? gav meredith[_2_] Excel Programming 1 April 20th 04 01:41 PM
Bob Phillips Mickey[_3_] Excel Programming 1 March 5th 04 08:46 PM


All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"