Декларируем:
Public Type OpenFilename
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" _
(ByRef pOpenfilename As OpenFilename) As Boolean
Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long
Аргументы: sTitle - строка которую выводим в заголовке формы открытия файла
Назначение: Вывод диалогового окна открытия файла
Возвращает: Строку - путь к выбранному файлу
Public Function GetFile(Optional sTitle As String = "Открыть файл") As String
Dim of As OpenFilename
Dim pos As Integer
GetFile = ""
of.lStructSize = Len(of)
of.hwndOwner = Application.hWndAccessApp
of.lpstrFilter = "MS Access Database (*.mdb)" & Chr$(0) & "*.mdb" & Chr$(0) & "All Files (*.*)" & Chr$(0) & "*.*"
of.nFilterIndex = 1
of.lpstrFile = String$(512, 0)
of.nMaxFile = 511
of.lpstrDefExt = "mdb"
of.lpstrTitle = sTitle
If GetOpenFileName(of) Then
pos = InStr(1, of.lpstrFile, Chr$(0))
GetFile = Left(of.lpstrFile, pos - 1)
End If
End Function
Ссылки по теме