Click on the Cancel button

W

Woody

Hello,

The following procédure opens a dialog box which allows to select a file.
I would like to capture the Click on the Cancel button to stop the
procedure.
How can I do that?
Thanks for your help

Woody

Dim oDialog As Office.FileDialog

Set oDialog = XLApp.FileDialog(msoFileDialogFilePicker) 'Opens a
dialog MS Office FilePicker
oDialog.Filters.Add "Fichiers Excel", "*.xls" 'Select
workbook .XLS
oDialog.Title = "Sélectionnez le fichier Excel" 'Title of
dialog
oDialog.AllowMultiSelect = False 'No multiple
selection
oDialog.Show 'Display the
dialog
If oDialog.SelectedItems.Count > 0 Then
NomClasseurXL = oDialog.SelectedItems(1)
MsgBox "Le classeur Excel sélectionné est : " & NomClasseurXL
End If
Set oDialog = Nothing
 
B

Bob Phillips

Dim oDialog As Office.FileDialog
Dim XLApp
Set XLApp = Application

Set oDialog = XLApp.FileDialog(msoFileDialogFilePicker) 'Opens a
dialog MS Office FilePicker
oDialog.Filters.Add "Fichiers Excel", "*.xls" 'Select
Workbook .XLS
oDialog.Title = "Sélectionnez le fichier Excel" 'Title of
Dialog
oDialog.AllowMultiSelect = False 'No multiple
Selection
If oDialog.Show Then 'Display the
Dialog
MsgBox "yes"
If oDialog.SelectedItems.Count > 0 Then
NomClasseurXL = oDialog.SelectedItems(1)
MsgBox "Le classeur Excel sélectionné est : " & NomClasseurXL
End If
End If
Set oDialog = Nothing


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
W

Woody

Bob,
I don't understand how this If oDialog.Show can tell me that the user
clicked on the Cancel button ?
 
B

Bob Phillips

Woody,

Try it and see.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
W

Woody

I did it. That works fine!

Thanks Bob

Bob Phillips said:
Woody,

Try it and see.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top