Activate Workbook after Opening

jeffwu

New Member
Joined
Jul 28, 2010
Messages
4
Hello

I'm running into a problem with a macro I've created. The macro is currently stored in WorkbookA.xls. I have it prompting an open dialog box to open the file WorkbookB.xls and execute a series of commands. The problem is, the macro keeps failing after I've selected WorkbookB.xls from the Open dialog box. How do I activate WorkbookB.xls immediately after opening it?

Also, is this possible if WorkbookB.xls is a variable file name, for example, it's named WorkbookB.xls on a Tuesday, but WorkbookC.xls on a Wednesday?


I've run across this forum so many times in searching for my Excel troubles, this is my first post. Thanks in advance!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
63,260
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

When you open a new workbook, that workbook, by default, should automatically become the new active workbook. If it is not, I would like to see exactly how your code is written.

You can "capture" the name of any active workbook in VBA like this:
MyWBName=ActiveWorkbook.Name

Then, if you are bouncing around between workbooks, you can come back to it like this:
Windows(MyWBName).Activate

This also makes the reference dynamic, which is great if the file names may change each day.
 

jeffwu

New Member
Joined
Jul 28, 2010
Messages
4
Thanks so much for the reply!

For some reason, the newly opened workbook wasn't defaulting to active. I continued to mess around with my syntax and used Windows(MyWBName).Activate and now all is well. Thanks again for the help, I'll probably end up finding my way back to this forum when I get stuck again.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,580
Messages
5,832,582
Members
430,144
Latest member
bruno92

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
Top