Thisworkbook.activate - semi working

James_Latimer

Active Member
Joined
Jan 20, 2009
Messages
415
EDIT! - I've found that once i click on the Excel instance with MainWkb open then the code below works fine - it seems i have to manually activate MainWkb the first time!?!?!?!?!?! Any ideas how to get around this?


Excel 2016 / Win 10

Hello fellow Excel'ers,

I am having some trouble switching between workbooks with VBA. I am simply trying to activate a workbook but it only semi-works...

I have a variable MainWkb that has been set as my workbook. I then have another instance QCWkb that i set to Workbooks.Open(file that i want to open).

I've tried the following:

Code:
MainWKb.Activate
and
Code:
MainWkb.Sheets(sheetnamehere).Activate

Although the workbook (MainWkb) is indeed activating, it is not being brought to the front. This means that i then have to minimise the opened workbook (QCWkb) before i can see my workbook (MainWkb).

I hope that this makes sense and that i'm not missing something blatantly obvious!

If anyone can shine some light on how to make another workbook activate and come to the front of the screen it would be much appreciated.

Thanks in advance.
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
OK... so i have it working, but i'm still unsure as to why it wasn't working before...

My code was opening another workbook (QCWkb), it then called another routine that adds a new sheet to MainWkb, i then called a message box (informs user of keypress to use etc) and then activated QCWkb. I found that when i don't call the message box then everything works just fine!?

Given that i try to follow the path of least resistance through life, i decided to 'sack off' the message box and i'll add the information to the worksheet instead.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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