+ Reply to Thread
Results 1 to 10 of 10

Command button(SEARCH) to open windows explorer to select file

  1. #1
    Registered User
    Join Date
    10-04-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    34

    Command button(SEARCH) to open windows explorer to select file

    hello there,

    i need you help becuase i am kind of stuck for now.

    i am designing a macro in excel using VBA and i have put in a few codes for now.

    i just want to know how is it possible to "code" the command button so that when clicked on, the windows explorer(just like when you have to open a file in microsoft word) will appear so that the user can select the file to be opened and once the user selects the file and clicks open, the result will appear in the textbox next to the button. but i dont want the file to be opened. i just want the result(path) of the file to appear in the textbox.

    this is because i have another button at the bottom of the macro that would run all the selected files at the end because there is actually 3 command buttons and 3 textboxes that i need to "collaborate" at the end.
    Last edited by sameerk0286; 10-24-2010 at 09:41 PM.

  2. #2
    Registered User
    Join Date
    10-07-2010
    Location
    Delft, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Command button(SEARCH) to open windows explorer to select file

    Hi,

    this is a piece of code I got from a co-worker once, just assign a button to it. Don't know if it applies to your situation but no harm in trying

    Please Login or Register  to view this content.
    Last edited by davesexcel; 10-07-2010 at 04:25 AM. Reason: Code tags required, Please read the Forum Rules

  3. #3
    Registered User
    Join Date
    10-04-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Command button(SEARCH) to open windows explorer to select file

    Thank you but i dont want the file to save the activesheet in another file. i want 1 tab(filtered) from the selected file to appear in the workbook having the MACRO.

    currently, with the code u gave me, it is saving the sheet that i want the result to appear in another workbook.


    FYI - it does not save the file...


    help


    thank you
    Last edited by sameerk0286; 10-07-2010 at 05:03 AM. Reason: Quoting previous post is not required

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Command button(SEARCH) to open windows explorer to select file

    sameerk0286
    the code finds the file
    Please Login or Register  to view this content.
    run it and look at the results.
    the answer to your question would be "yes"
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  5. #5
    Registered User
    Join Date
    10-07-2010
    Location
    Delft, Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Command button(SEARCH) to open windows explorer to select file

    maybe something like this?

    Please Login or Register  to view this content.

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Command button(SEARCH) to open windows explorer to select file

    or to place in the text box
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-04-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Command button(SEARCH) to open windows explorer to select file

    Thank you so much. i just wanted the file path to appear in the textbox so i just changed GetSaveAsFilename to GetOpenFilename.

    it worked though and i am able to see the file path in the textbox. i have another button at the bottom of the MACRO that will "generate" the files once clicked by the user but i will do the calling of files tmrw.

    thank u again

  8. #8
    Forum Contributor
    Join Date
    01-31-2007
    Location
    Aschaffenburg, Germany
    MS-Off Ver
    Office 2013
    Posts
    104

    Re: Command button(SEARCH) to open windows explorer to select file

    Maybe this is what you are looking for: a file dialog that enables the user to select any file
    You may as well allow files from several applications. They just need to be separated using | (e.g. strFileType = "Excel|Word", strFileExt = "*.xl*|*.do*"). This will enable the user to select options from the Files of Type: drop down.

    Please Login or Register  to view this content.
    Mike 1001
    _________________________
    Let's keep trying, one day we'll succeed!

  9. #9
    Registered User
    Join Date
    10-04-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Command button(SEARCH) to open windows explorer to select file

    Quote Originally Posted by Mike1001 View Post
    Maybe this is what you are looking for: a file dialog that enables the user to select any file
    You may as well allow files from several applications. They just need to be separated using | (e.g. strFileType = "Excel|Word", strFileExt = "*.xl*|*.do*"). This will enable the user to select options from the Files of Type: drop down.

    Please Login or Register  to view this content.

    Thanl you but how do i change it and where do i change it to be able to call the spreadsheet that i want to be opened?


    thank you again

  10. #10
    Forum Contributor
    Join Date
    01-31-2007
    Location
    Aschaffenburg, Germany
    MS-Off Ver
    Office 2013
    Posts
    104

    Re: Command button(SEARCH) to open windows explorer to select file

    Sorry, sameerk0268, I have not been online for a while...

    You leave the SelectFile routine as it is. You just have to adjust what example I had given you in the Test routine.
    What I usually do is to find a strFilePath which might be usefule (even when the probability for that is low), taken from some (named) cell somewhere in the spreadsheet. Once the user has selected a file (and a folder), I write this folder's name into that cell in the spreadsheet for using it next time as the initial folder name.

    HTH

+ 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