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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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