+ Reply to Thread
Results 1 to 4 of 4

Button to Prompt for Filename to be Used

  1. #1
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Button to Prompt for Filename to be Used

    So I wrote all my macro and it works perfectly but I have a little quirk I regarding Filenames. The marco reference a file that follows this naming scheme "fname-09-08-15". So it's first name-year-month-day. This file is received every mid and end cycle.

    I would like to be able to pass that file name as an parameter to the macro so the i dont have to go in and do a manual change everytime. I have a button on my worksheet that runs the macro.

    My question is: is there a way so that when i click the button, the user is prompted to input the filename or perhaps browse for it so it can be used? That way i can use the input of the button perhaps as input to the marco...?!?! (my macro only works when both files are open at the same time under one instance of excel - not sure why but didnt bother).

    If there is a better way, please feel free to suggest. This is my 3rd day coding in VB and I've done a lot so far. Thanks!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Button to Prompt for Filename to be Used

    A little sub to demonstrate how you can browse to select a file and find out the path AND the file name chosen in on go:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Button to Prompt for Filename to be Used

    Thanks for that. i tried playing around with it for a while but didn't get anywhere. I think I lack some basics in VB?

    I'll try to give some more info and some Pseudocode. Below is how my Sub starts. The Workbook containing the data I need to pull will be called WB-09-08-15.xls in what follows.

    Please Login or Register  to view this content.
    Since the date changes every 15 days (the next being 09-08-30), I would like to be able to perhaps pass the filename as a parameter to the main sub.
    So i would have

    Please Login or Register  to view this content.
    The tricky part is the sub runs by clicking a button that is in my worksheet.
    So ideally I would like to be able to
    1- Click the button.
    2- Be prompted to enter the FileName or browse for it.
    3- Have that Filename passed as a parameter.

  4. #4
    Registered User
    Join Date
    08-07-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Button to Prompt for Filename to be Used

    bump in case anyone can follow up.


    Thanks!

+ 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