Just in case anyone is interested, here's the code I ended up putting
together that does what I wanted.
Jeff
1. Add these declarations at the start of your module, before the
first
procedure:
Declare Function GetOpenFileName _
Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) _
As Boolean
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
End Type
2. Add this function somewhere in your module:
Function FileName()
Dim ProjectFile As OPENFILENAME
With ProjectFile
.lStructSize = Len(ProjectFile)
.hwndOwner = 0
.hInstance = 0
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = Chr$(0)
.flags = 0
' Following is the Dialog Title
.lpstrTitle = "Select Project File"
' Following is a filter for the type of file -
' (a) a literal which is displayed in the Files of
Type box,
and
' (b) a filter restricting the files shown
' Change these according to your needs.
.lpstrFilter = "Microsoft Project Files (*.mp*)" +
Chr$(0) +
"*.mp*" + Chr$(0)
End With
If GetOpenFileName(ProjectFile) Then
FileName = Trim$(ProjectFile.lpstrFile)
Else
Exit Function
End If
End Function
3). Finally call the function when you need it, for example:
OPENFILENAME = FileName()
If OPENFILENAME = "" Then
Exit Sub
End If
strFileName = OPENFILENAME 'work with strFileName like any
other
variable