GetOpenFilename in MS Project RRS feed

  • Question

  • I'm writing a script that should allow users to browse for a resource pool. I'm stuck trying at the browse part (Set PoolFileName = Application.GetOpenFilename(Title...). GetOpenFilename is not a method in MS project vba.

    My code is as follows:

    Public Sub PoolCheck()
        Dim pjApp As Application
        Dim err As Boolean
        Dim answer As Integer
        Dim PoolFileName As String
        Application.ScreenUpdating = False
        Set pjApp = MSProject.Application
        On Error GoTo ErrMsg
        err = pjApp.ResourceSharingPoolRefresh 'This will create an error if no resource pool is linked
        Application.ScreenUpdating = True
    Exit Sub
        answer = MsgBox("This Project Plan is not linked to a resource, would you like to link it to a resouce pool now?", vbYesNo + vbQuestion, "Resource Pool")
        If answer = vbYes Then
            Set PoolFileName = Application.GetOpenFilename(Title:="Please choose a file to open")
            Application.ResourceSharing Share:=False, Name:=PoolFileName, Pool:=True
         'do nothing
        End If
        Application.ScreenUpdating = True
    End Sub
    Appreciate your suggestions!

    Sunday, May 7, 2017 5:14 PM


All replies

  • Project VBA does not have the Excel GetOpenFileName method. However if you have access to an Excel application object you can use it. EG:

    xlApp.GetOpenFileName (etc.)

    If you are not working with Excel as well, you need to use a windows API. You can copy ones written for Access unchanged. Try:

    Rod Gill
    Author of the one and only Project VBA Book and VBA developer.

    • Marked as answer by Huismu5 Monday, May 8, 2017 4:59 PM
    Monday, May 8, 2017 10:25 AM
  • Awesome Rod! I used the Access API and that did the trick. I haven't had time to study the code, but to make it work I had to comment out all references to the "HomeWindow" (e.g. hwnd = Application.hWndAccessApp).
    Monday, May 8, 2017 5:13 PM