PDA

View Full Version : Solved: GetOpenFilename in MS Project



SeanS
09-29-2004, 07:12 AM
In MS Project 98 I am trying to write a macro that will prompt a user for an Excel file that they will have stored somewhere on their PC. When I have done this in the past in Excel, I have used Excel's method GetOpenFilename.

However this method is not available in MS Project. Is there another method or a similar way of doing this in MS Project??

Thanks for your help, Sean.

TonyJollans
09-29-2004, 07:55 AM
Hi Sean,

Welcome to VBAX!

For some reason, it's not available in all the Office apps, so I think you'll have to code it yourself using the API ..

At the start of your module ..


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


And then in your Sub (or Function) ..


Dim ProjectFile As OPENFILENAME
Dim ProjectFileName As String

:
:

With ProjectFile

.hwndOwner = 0
.hInstance = 0
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrInitialDir = Chr$(0)
.flags = 0
.lpstrTitle = "Select Project"
.lpstrFilter = "Projects (*.mpp)" + Chr$(0) + "*.mpp" + Chr$(0)

.lStructSize = Len(ProjectFile)

End With

If GetOpenFileName(ProjectFile) Then _
ProjectFileName = Trim$(ProjectFile.lpstrFile)

SeanS
09-29-2004, 08:07 AM
Cheers Tony - That worked great.. I wasn't looking forward to re-inventing the wheel again..!!! :cool