|
|
Диалог открытия файла (метод FileDialog)
Private Sub cmdTest01_Click()
Dim sFilePuth As String
sFilePuth = GetFilePath(, , "Images", "*.gif; *.jpg; *.jpeg; *.png")
End Sub
Функция:
Public Function GetFilePath(Optional sInitDir As String = "", Optional sFileNameMask As String = "", _
Optional sFilterName As String = "Любые файлы", Optional sFilterMasks As String = "*.*") As String
On Error GoTo GetFilePath_Err
If Dir(sInitDir, vbDirectory) = "" Then sInitDir = CurrentProject.Path
If Right(sInitDir, 1) <> "" Then sInitDir = sInitDir & "\"
With Application.FileDialog(1)
.Title = "Поиск файла: " & sFileNameMask
.InitialFileName = sInitDir & sFileNameMask
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add sFilterName, sFilterMasks, 1
.Show
If .SelectedItems.Count > 0 Then
GetFilePath = .SelectedItems(1)
End If
End With
GetFilePath_Bye:
Exit Function
GetFilePath_Err:
MsgBox "Ошибка " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"в процедуре: GetFilePath", vbCritical, "Error!"
Resume GetFilePath_Bye
End Function
|
|