Function FileOpen(oCD As CommonDialog, Optional ByVal sTitle As String = "Choix du fichier", _
Optional ByVal sFiltreContent As String = "*.*") As String
' CHOIX D'UN FICHIER pour VB6, VBA
' mettre un contrôle "CommonDialog1" sur une feuille (ici Form1)
With oCD
.FileName = "" 'Efface,(re)met un fichier
.Flags = cdlOFNHideReadOnly + cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNFileMustExist
.DialogTitle = sTitle
.Filter = sFiltreContent
.ShowOpen 'ouverture
FileOpen = .FileName 'récupère le nom
End With
End Function
Private Sub Command1_Click()
MsgBox FileOpen(Form1.CommonDialog1)
End Sub