PDA

View Full Version : Activate a workbook



xljunkie
05-20-2011, 01:17 PM
Bear with me please as this is basic and I'm just starting to learn.

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)?

nepotist
05-20-2011, 01:23 PM
You use arrays to store all the 12 months (use the 3 letter naming convention) and then use the array to open the workbook.
Dim Months (1 to 12 ) as string

Months (1) = "JAN"
.
.
.
Months(12)="Dec"

Then use a loop to search for the workbook with the name contained in array and if a name matches then perform your action

xljunkie
05-21-2011, 11:01 AM
Thanks for the reply. I'm reading up on how to do loops right now. I'll try some things out at work next week.