Best I can understand, reference will need to be added, since Commmon Dialog is not standard equipment.
Try Comdlg32.ocx, Microsoft Common Dialog Control.
P.S. Once you set the Reference, and add the control to the Toolbox, CommonDialog will be found in Object Browswer; select it and press F1 (Help) for information on the control.
The Example will be confusing for VBA programmers; the default names of controls are strictly VB, and there is no (imho) way to construct an Option Button array in VBA. This message was edited by stevebausch on 2002-09-03 07:17
Using the cmdlg can be useful for Filtering as the getopen file VBA doesn't offer this option, so unless you are looking to do something withit that can't be done using STD VBA Getopenfilename then Stick to GetOpenfilename, otherwise try this;
Note: How it builds the Type structure up that you will need for the API call.
There are also a number of other properties and const that you can use.
Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" ( _
pOpenfilename As OPENFILENAME) As Long
Private 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
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
OpenFile.lStructSize = Len(OpenFile)
sFilter = "my XlFiles (*.xls)" & Chr(0) & "*.xls" & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrInitialDir = "C:"
OpenFile.lpstrTitle = "Use the Cmdlg API and NOT Ocx"
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
MsgBox "The User pressed the Cancel Button"
MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)