+ Reply to Thread
Results 1 to 2 of 2

Refer to Unknown File Name

  1. #1
    Lynn
    Guest

    Refer to Unknown File Name

    I need to switch between 2 open files in a macro. I know the name of one
    file but not the other. What code can I use to activate the workbook that I
    don't know the name of?

  2. #2
    JMB
    Guest

    RE: Refer to Unknown File Name

    Maybe

    Activewindow.ActivateNext

    but it wouldn't be my first choice as it depends on there being only two
    workbooks open.


    Can you use the macros in the first workbook to open the second during
    execution? Since you don't know the file name, I assume the user has to open
    the second book.

    Sub test()
    Dim wkbTest As Workbook
    Dim varFName As Variant

    varFName = Application.GetOpenFilename
    If varFName = False Then End

    Set wkbTest = Workbooks.Open(Filename:=varFName)

    End Sub


    Then you can use the object variable, wkbTest (change variable name if you
    like) to refer to the second book.

    wkbTest.Worksheets("Sheet1").Range("A1").Value = 5




    "Lynn" wrote:

    > I need to switch between 2 open files in a macro. I know the name of one
    > file but not the other. What code can I use to activate the workbook that I
    > don't know the name of?


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1