VBA - Activate a workbook

xljunkie

Board Regular
Joined
May 20, 2011
Messages
92
Pretty new to VBA so I'm in the beginning stages of learning this stuff.

I have 3 workbooks open:

1. Query.xls
2. Macro.xls
3. April.xls

The 3rd one's file name changes from month to month. I want to write code in the Macro workbook that will activate the April workbook.

Is there such a way that I can have a list of months (Jan, Feb, Mar, etc) within the Macro workbook and have code activate the workbook whose first 3 letters are contained in this list? Is there a better way to do it (i.e. have the code activate whatever workbook is not named Query or Macro)?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Try like this

Code:
Sub b()
Dim wb As Workbook
For Each wb In Workbooks
    If wb.Name <> "Query.xls" And wb.Name <> "Macro.xls" Then
        wb.Activate
        Exit For
    End If
Next wb
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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