Consulting

Results 1 to 4 of 4

Thread: Solved: filedialog

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    Solved: filedialog

    I am using the below to prompt the user to select files which I will then import into excel

    Application.FileDialog msoFileDialogFolderPicker
    It is all working fine but I want to capture if the user at any time presses "cancel" The filedialog loops a few times with different prompts.

    I want to capture a cancel and then delete all the data that has been imported so far so that when they press import the next time there is not any data in the sheets.

    I tried If .Show = -1

    But it went all funny on me

    Help!

  2. #2
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    loops sending me loopy!

    I

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    My Excel 2004 doesn't recognize the FileDialog method, but if it acts like the Excel dialogs I can access, it returns a boolean value.

    If Application.FileDialog(msoFileDialogFolderPicker) Then
        MsgBox "user did something"
    Else
        MsgBox "Cancel pressed"
    End If

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,735
    Location
    Try this

    Sub ABC()
        With Application.FileDialog(msoFileDialogFolderPicker)
        .Show
        If .SelectedItems.Count = 0 Then
            MsgBox "You pressed Cancel"
        Else
            MsgBox .InitialFileName
        End If
        End With
    End Sub
    Paul

Posting Permissions

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