You can't. But you can do it in code. The code below was from an example on a web site and is perfectly ok to use. It's only calling Windows API after all.
DECLARATIONS
Type tagOPENFILENAME
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
YOU STILL NEED Comdlg32.dll
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OPENFILENAME As tagOPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (OPENFILENAME As tagOPENFILENAME) As Long
Dim OPENFILENAME As tagOPENFILENAME
Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000
Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0
Function OpenCommDlg(cForm As Form, cFilter As String, cStartDir As String) As String
Dim Message$, FileName$, FileTitle$, DefExt$
Dim Title$, szCurDir$
Dim APIResults As Long
Dim i As Integer
On Local Error GoTo 0
'* Allocate string space for the returned strings.
FileName$ = Chr$(0) & Space$(255) & Chr$(0)
FileTitle$ = Space$(255) & Chr$(0)
'* Set up the default directory
If cStartDir = "" Then
cStartDir = CurDir$ & Chr$(0)
Else
cStartDir = cStartDir & Chr$(0)
End If
'* Set up the data structure before you call the GetOpenFileName
OPENFILENAME.lStructSize = Len(OPENFILENAME)
OPENFILENAME.hwndOwner = 0&
OPENFILENAME.lpstrFilter = cFilter
OPENFILENAME.nFilterIndex = 1
OPENFILENAME.lpstrFile = String(257, 0)
OPENFILENAME.nMaxFile = Len(OPENFILENAME.lpstrFile) - 1
OPENFILENAME.lpstrFileTitle = OPENFILENAME.lpstrFile
OPENFILENAME.nMaxFileTitle = OPENFILENAME.nMaxFile
OPENFILENAME.lpstrTitle = "Find"
OPENFILENAME.flags = 0
'OPENFILENAME.lpstrCustomFilter
'OPENFILENAME.nMaxCustFilter
'OPENFILENAME.nFileOffset
'OPENFILENAME.nFileExtension
'OPENFILENAME.lCustData
'OPENFILENAME.lpfnHook
'OPENFILENAME.lpTemplateName
OPENFILENAME.hInstance = GetWindowLong(cForm.hwnd, 0)
OPENFILENAME.lpstrInitialDir = cStartDir
'* This will pass the desired data structure to the Windows API,
'* which in turn uses it to display the Open Dialog form.
APIResults = GetOpenFileName(OPENFILENAME)
If APIResults <> 0 Then
'* Note that FileName$ will have an embedded Chr$(0) at the
'* end. You may wish to strip this character from the string.
For i = 1 To Len(OPENFILENAME.lpstrFile) - 1
If Asc(Mid(OPENFILENAME.lpstrFile, i, 1)) = 0 Then
OPENFILENAME.lpstrFile = Left$(OPENFILENAME.lpstrFile, i - 1)
Exit For
End If
Next i
OPENFILENAME.lpstrFile = Trim$(OPENFILENAME.lpstrFile)
' i = InStr(OPENFILENAME.lpstrFile, 0)
' If i > 0 Then
' OpenCommDlg = Left$(OPENFILENAME.lpstrFile, i - 1)
' Else
OpenCommDlg = OPENFILENAME.lpstrFile
' End If
Else
OpenCommDlg = ""
End If
End Function
I commented out some bits that didn't work.
And you call it thus
cImportFileName = OpenCommDlg(Forms!ImportOrders, "htm(*.htm)" & Chr$(0) & "*.htm;*.htm" & Chr$(0), cPath)
If cImportFileName = "" Then
i = MsgBox("No File Selected", vbOKOnly, APPLNAME)
Exit Sub
End If
It's actually a lot less frightening than it looks. Copy and paste and don't read it! I have code for the other common dialogues too.
As it goes on a bit, mail me and I'll send it.
Another one for the Useful Bits of Code Forum?
Peter Meachem
peter@accuflight.com