Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Browsing (VBA/Excel/2000 & 2003)

    Can someone please provide me with some code that will allow the user to browse to a folder and select a file. I don't want to open the file, merely determine the path and filename?

    I have been using the following code successfully to browse and find a folder, but don't understand it sufficiently to convert it to my immediate needs.
    <hr> Public Function GetFolderDlg(Optional RootFolder As Variant, _
    Optional Title As String = "Select a Folder") As String
    On Error Resume Next
    GetFolderDlg = Replace(CreateObject("Shell.Application").BrowseFo rFolder(0, _
    Title, 0, RootFolder).Items.Item.Path & "", "", "")
    End Function<hr>
    Many thanks in advance.
    Regards
    Don

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Browsing (VBA/Excel/2000 & 2003)

    Like this:

    <div style="width: 100%; background-color: #FFFFFF;"><code><font color=black><font color=blue>Sub</font color=blue> GetOpenFileNameExample3()
    <font color=blue>Dim</font color=blue> lCount <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>
    <font color=blue>Dim</font color=blue> vFilename <font color=blue>As</font color=blue> <font color=blue>Variant</font color=blue>
    <font color=blue>Dim</font color=blue> sPath <font color=blue>As</font color=blue> <font color=blue>String</font color=blue>
    <font color=blue>Dim</font color=blue> lFilecount <font color=blue>As</font color=blue> <font color=blue>Long</font color=blue>
    sPath = "c:windowstemp"
    ChDrive sPath
    ChDir sPath
    vFilename = Application.GetOpenFilename("Microsoft Excel files (*.xls),*.xls", , "Please select the file(s) to import", , <font color=blue>False</font color=blue>)
    <font color=blue>If</font color=blue> TypeName(vFilename) = "Boolean" <font color=blue>Then</font color=blue> <font color=blue>Exit</font color=blue> <font color=blue>Sub</font color=blue>
    <font color=448800>'Now open the selected file</font color=448800>
    Workbooks.Open vFilename
    <font color=blue>End</font color=blue> <font color=blue>Sub</font color=blue></font color=black></code></div hiblock>
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Browsing (VBA/Excel/2000 & 2003)

    Hans and Jan Karel
    Thank you both so much. As always timely and very beneficial.
    Regards
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Browsing (VBA/Excel/2000 & 2003)

    Excel has the Application.GetOpenFilename method. For example:

    Dim varFile As Variant
    varFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If varFile = False Then
    ' user clicked Cancel - exit procedure or issue a warning
    MsgBox "No file selected"
    Else
    ' user clicked OK - varFile contains the complete path and filename
    MsgBox "You selected " & varFile
    End If

Posting Permissions

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