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!
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,178
Office Version
365
Platform
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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,565
Messages
5,512,090
Members
408,879
Latest member
dilipsny

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top