Consulting

Results 1 to 4 of 4

Thread: How do I open variable file in Excel?

  1. #1

    How do I open variable file in Excel?

    How do I open a file in VBA or a macro to open a file# that is entered into cell B1?

    where ACCT is just a number refering an acct# which also
    is the acct # and .xls
    If B1 is 12345 then it opens 12345.xls, etc.(over 100 files
    on the drive)

    What I would need is something like...

    ActiveCell.Range("B1").select
    Let ACCT = ActiveCell
    Workbooks.Open Filename:="C:\subdirectories\[ACCT].xls"
    But I cannot find anything that will do something like this... (Is it possible? )

    Many thanks!!
    Robert

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hi Robert, welcome to VBAX!

    You can use something like this ..


    On Error GoTo NotOpen
        Workbooks(Range("B1").Text & ".xls").Activate
        Exit Sub
    NotOpen:
        Err.Clear
        Workbooks.Open "C:\Documents and Settings\Rob\Desktop\" & Range("B1").Text & ".xls"
        On Error GoTo 0
    .. in a routine. This should work for you. Let us know how it works.

    Btw, I moved your post into the Excel Help forum.

    Edit: Error Handling

  3. #3
    Zack,

    It works!! Thanks very much!!

    I really appreciate it!!

    Robert

  4. #4
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    No problem at all Robert!

    Btw, did you know that you can mark your own threads as Solved? Goto Thread Tools --> Mark Solved --> Perform Action.

    Take 'er easy!

Posting Permissions

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