Don't know how to program button to open File explorer that can open any file type

  • All I need is simple:


    The code should


    1. Open file explorer after I click the "Open file explorer" button on a worksheet.


    2. After selecting a document in a file explorer and clicking open the document needs to simply open regardless of what file type it is. Wether it be PDF, JPG.,Word Document, Excel document. etc.


    I have spent an entire day and then some trying to figure this out. The closest I have gotten to this is is



    Code
    Application.GetOpenFileName




    I have searched EVERYWHERE for this so please don't ask me if I have googled this or searched other forums because I HAVE. All of the answers I have gotten have me directed to solutions that center around selecting excel files. I need the file explorer to open ANY file I select not just excel files. I don't need a file path extracted from the selected document and pasted to the excel sheet. I don't need the document name extracted from the selected document in the file explorer and put in a text box in a userform. I just need the document no matter the file type to simply open. I have asked this question on StackOverflow and it got downvoted 4 times. Not sure why but I am sure it's because those who have downvoted this feel the question has been asked in some way or another by someone else...but here we are...my question has not been answered and I have googled this multiple times in multiple ways and nothing comes up that helps.


    If anybody has anything they could offer that would help this would be huge.


    Stackoverflow: https://stackoverflow.com/ques…en-any-file-via-excel-vba


    Thank you in advance

  • Hi 12moshikamj,


    Sounds like a job for the old DOS shell script:



    Regards,


    Robert

  • A GetOpenFilename alternative to select a single file of any type would be:


    Code
    sFile = Application.GetOpenFilename(FileFilter:="All Files (*.*),*.*", Title:="Select File to Open")


    Even if the FileFilter is set to eg, FileFilter:="Excel Files (*.xl*),*.xl*" you can always open any file you wish by typing *.* or *.jpg or whatever in the File name box when the dialog opens and it will display all matching files, the filter is just the default filter.


    You could also combine default filters eg:

    Code
    sFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xl*),*.xl*, All Files (*.*),*.*", Title:="Select File to Open")


    Then you can select which filter to use from the dropdown box in the open file dialog, and the order in which you declare them will determine the order in the dropdown.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!