+ Reply to Thread
Results 1 to 8 of 8

Activate workbook from input box

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Activate workbook from input box

    Greetings, Gurus.

    If a user downloads a report in excel format it is always opened as "DeliveryReport(1).xls", but the number could be anything from 1 to 20. If I want the user to be able to run a macro from my existing workbook on this newly opened file, I need them to express what this variable number is. My thought was to just have an input box open and ask them to input the number, then the macro could activate that newly opened workbook.

    I don't know if it's because of the parenthesis or what, but for some reason I can't enter it this way:
    Please Login or Register  to view this content.
    Anybody have any ideas what I'm doing wrong?

    Thanks in advance for any help you can offer.
    Last edited by [email protected]; 08-06-2008 at 04:07 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    If they open it, then it would be the activeworkbook.

    Try using FileDialog and let them click and pick. Your macro can then open it and do its thing.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Thanks for the reply, Kenneth. Not sure what FileDialog does, or how to apply it. The idea is that this macro will be used by novice users, and I have no idea how many different instances of Excel they will have open when they run the macro. I realize the report is active when they open it, but then when they go back to the workbook containing the macro, ThisWorkbook becomes the active workbook.

    Ideally, to keep it simple for novice users, I just wanted them to have to click a button and enter a number to identify and activate the report. Then I would set it as wbTemp, and could switch back and forth in the macro to perform all my actions from there.

    I think the parentheses in the filename are causing the syntax error. Can you think of any way around this, keeping it simple for novice users, (and someone with only a basic understanding of VBA).

    Thanks again for any help offered!

    Hutch

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Good morning again, Gurus.

    The fact that none of the mods have responded to this thread leads me to believe either it's not possible, or I'm going about it the wrong way.

    If a user has several workbooks open, what's the best method to assign a variable to another workbook, (with a varying name), so that the code can swap between the new workbook and ThisWorkbook? I plan to attach the code to a button click.

    Any suggestions appreciated.

    Have a good one!

    Hutch

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Think you missed a "&"

    Try
    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    Here is how to get the name of a file using FileDialog.
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    ****** ******

    I'm an idiot. Thanks, that fixed me right up.

    ****** ******

  8. #8
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Morning, Kenneth. Your message came through while I was responding to VBA Noob. It works fine by just adding the "&" that was missing, but I'm going to check yours out, too, to see which one is easier for the user. I appreciate your help.

+ 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