+ Reply to Thread
Results 1 to 3 of 3

How to use FileDialog in Excel VBA?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-03-2013
    Location
    weel count
    MS-Off Ver
    Excel 2003
    Posts
    6

    How to use FileDialog in Excel VBA?

    Hi,

    In Excel VBA, I use the following code to show the FileDialog box and select a new folder:

    Private Sub CommandButton1_Click()
    With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = ThisWorkbook.Path
    .Show
    TextBox1 = .SelectedItems(1)
    End With
    End Sub

    After the dialog box appears, if, however, I change mind and don't want to select a new folder and click the OK button or Cancel button, an error will pop up: "Path does not exist....". Any thing I am doing wrong?

    Thank you in advance.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to use FileDialog in Excel VBA?

    .InitialFileName = ThisWorkbook.Path
    if  .Show = 0 then exit sub 
    TextBox1 = .SelectedItems(1)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-03-2013
    Location
    weel count
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: How to use FileDialog in Excel VBA?

    Thank you shg.

    I have just tried your code and that workd fine when I click the Cancel button. However when I click the OK button, the error massage still pop up: "Path does not exist....".

+ 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