Standard FileOpen Window

J

Jeff Jones

I've written a little group of macros that take a text file to build a
schedule with its data. I've been unable to get the standard
"Filename = Application.GetOpenFilename()" function to work because I
get an error message stating that the Object doesn't support this
property or method."

My question is, have any of you gotten a standard file open window to
work with MS project?

Thank you,
Jeff
 
J

Jeff Jones

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
 
M

Microsoft Public

Hi,

For Project 2002 and 2003 you can also use the File Browse method in the
Office library.
 
J

Jeff Jones

Thank you Jack. It will be fun to wander around the macros on your
site.

Take care,
Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top