Consulting

Results 1 to 3 of 3

Thread: Activate a workbook

  1. #1
    VBAX Newbie
    Joined
    May 2011
    Posts
    2
    Location

    Activate a workbook

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

  2. #2
    VBAX Mentor
    Joined
    Aug 2008
    Posts
    323
    Location
    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
    I am a Newbie, soon to be a Guru

  3. #3
    VBAX Newbie
    Joined
    May 2011
    Posts
    2
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •