PDA

View Full Version : Solved: filedialog



philfer
12-31-2007, 12:30 PM
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!

philfer
12-31-2007, 12:39 PM
I

mikerickson
12-31-2007, 03:41 PM
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

Paul_Hossler
12-31-2007, 07:38 PM
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