Make most recently open workbook active window

dcoledc

Active Member
Joined
May 6, 2010
Messages
403
I am not quite sure how to ask this question b/c I am not sure of the correct terminology but here it goes. I have 2 workbooks each with their own closing procedures. Let's assume one workbook is open and I open the 2nd workbook from a macro in the 1st. How do I make the second book assume the activewindow position? Let me give an example of what I mean to better explain. If I have both workbooks open and I hit the red x in the upper right corner, it runs the before close procedures for the first workbook. So far I have created variables to bypass the before close sub from wb 1 but it is getting complicated. It occurred to me that perhaps there is some simple solution that makes the 2nd workbook the activewindow allowing its before close sub to run instead of wb 1's.

Help please.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
The premise of your question is still not clear because you wrote this:

"Let's assume one workbook is open and I open the 2nd workbook from a macro in the 1st. How do I make the second book assume the activewindow position?"

Based on the literal interpretation of that, unless you have code to force activation otherwise in your Open procedure, at the moment you open another workbook, or add another workbook for that matter, said workbook *is* the active workbook.

So what is the problem? If as you say you are "hit[ing] the red x in the upper right corner" then that means you are closing all the workbooks. As long as they are all closing anyway, what difference does it make which one was active since they will both end up closed, with their (presumably) BeforeClose events running as you have coded them.
 
Upvote 0
I am new to VBA and am certain I am probably not using the correct language. Having said that, in each workbook I have made it so the user must use the exit buttons I have created. So when the user hits the red x it will give them a message telling them to use mine. Using mine forces a save under a different name as well as a few other procedures. The procedures differ between the 2 workbooks. So when the user hits the red x in the 2nd wb it gives the msgbox from the 1st workbook when I want them to see the message from the 2nd workbook.

There may be better ways of accomplishing what I want accomplished but with my limited VBA knowledge this is what I have created. Again, to this point, I have set variables that will bypass wb 1's closing event allowing wb 2's to take over.

I guess my question is why does it run wb 1's first and how can I make it run wb 2's instead without setting a variable?

It my be my limited knowledge not of VBA but of the general basics of windows that is holding me back.

Thoughts?
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top