Consulting

Results 1 to 3 of 3

Thread: Solved: GetOpenFilename in MS Project

  1. #1
    VBAX Regular
    Joined
    Sep 2004
    Posts
    10
    Location

    Solved: GetOpenFilename in MS Project

    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.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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 ..

    [VBA]
    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
    [/VBA]

    And then in your Sub (or Function) ..

    [VBA]
    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)
    [/VBA]
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    VBAX Regular
    Joined
    Sep 2004
    Posts
    10
    Location
    Cheers Tony - That worked great.. I wasn't looking forward to re-inventing the wheel again..!!! :cool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •