Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: VBA to switch between open workbooks

  1. #1
    New Member
    Join Date
    Dec 2008
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA to switch between open workbooks

    Hi, I'm trying to get some macros to combine data from two open workbooks, and I can't figure out the commands to switch from the active workbook to the other open workbook and back. I'm new to VBA and just learning the ropes. All I can figure out is how to switch to another workbook with an exact name. If I record the macro to go to a recent file, for example Window > 1 (filename), the code that I get in VBA is Windows("filename").Activate. This doesn't translate to when I have two different workbooks with different filenames open.

    Make sense? I'm a bit confused myself. Maybe just a list of basic workbook-switching techniques or commands would be useful.

    - Michael

  2. #2
    Board Regular Datsmart's Avatar
    Join Date
    Jun 2003
    Location
    Olympia
    Posts
    7,985
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to switch between open workbooks

    You don't have to name them -you can refer to them in the order that they were opened
    ie:
    Workbooks(1)
    Workbooks(2)
    Workbooks(3)

    See this thread:
    http://www.mrexcel.com/board2/viewtopic.php?p=1243848
    John

  3. #3
    New Member
    Join Date
    Dec 2008
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to switch between open workbooks

    mis-post
    Last edited by mbryant; Dec 22nd, 2008 at 04:40 PM.

  4. #4
    New Member
    Join Date
    Dec 2008
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to switch between open workbooks

    I tried using Windows(Workbook(1)).Activate and Windows("Workbook(1)").Activate and several other combinations and couldn't get it to work. Is there something I'm doing wrong? How do I get it to return the right thing (Workbook(x))?

  5. #5
    Board Regular
    Join Date
    May 2003
    Posts
    1,042
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA to switch between open workbooks

    Quote Originally Posted by mbryant View Post
    I tried using Windows(Workbook(1)).Activate and Windows("Workbook(1)").Activate and several other combinations and couldn't get it to work. Is there something I'm doing wrong? How do I get it to return the right thing (Workbook(x))?
    Code:
    Sub ChangeWorkbook()
    Application.Workbooks(1).Activate
    End Sub
    =IF(U:U="don't care where you are going",UR:UR<>"LOST",UR:UR="LOST")

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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