none
How to Call a proc which is in GLobalMPT RRS feed

  • Question

  • Hi,

    In several Project.MPP files I have an event Project_BeforeSave which have to call a VBA proc stored in the Global.MPT file.

    How can I do that?

    Thanks for your help

    Thursday, May 8, 2014 10:25 AM

Answers

  • Hi WLID,

    pressing submit gave me the good idea. Put following code into a project to provide to your users or change it to Project_Open to run.

    Sub SetreferenceGlobalMPT()
    
    On Error Resume Next 'we don't want error messages
    'Set reference on global.mpt
    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\MS Project\14\1033\global.mpt"
     
        Select Case Err.Number
        Case Is = 32813
             'Reference is set - no activity required
        Case Is = vbNullString
             'Reference was set without issue
        Case Else
             'Unknown error
             MsgBox "Unfortunately there was an error. Please provide information to ...." & Err.Number & " " & Err.Description
        End Select
        On Error GoTo 0
    
    End Sub
    

    Please change language number to yours, also version. Just check your own cache location for that.

    After running this at least once, calling a macro from global.mpt should work.

    Good luck!
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Thursday, May 8, 2014 8:10 PM
    Thursday, May 8, 2014 4:20 PM
    Moderator

All replies

  • Hi WLID,

    how many users will need this? So far, I am only aware to provide this by performing following steps up frunt before:

    • Open VBA Editor
    • Tools - References
    • Browse
    • Open folder of global.mpt, change Files of Type to Microsoft Project Files
    • Select Global.mpt and close all dialogs

    Afterwards, you can start your macro with just "call macroname"

    Unfortunately, this reference does not have a guid as other references. To add a references programmatically, I am currently only able to do this using its guid. So I am not aware of any programmatical option to add this reference.

    I will update here, when I have a better idea.

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!


    Thursday, May 8, 2014 4:01 PM
    Moderator
  • Hi WLID,

    pressing submit gave me the good idea. Put following code into a project to provide to your users or change it to Project_Open to run.

    Sub SetreferenceGlobalMPT()
    
    On Error Resume Next 'we don't want error messages
    'Set reference on global.mpt
    Application.VBE.ActiveVBProject.References.AddFromFile "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\MS Project\14\1033\global.mpt"
     
        Select Case Err.Number
        Case Is = 32813
             'Reference is set - no activity required
        Case Is = vbNullString
             'Reference was set without issue
        Case Else
             'Unknown error
             MsgBox "Unfortunately there was an error. Please provide information to ...." & Err.Number & " " & Err.Description
        End Select
        On Error GoTo 0
    
    End Sub
    

    Please change language number to yours, also version. Just check your own cache location for that.

    After running this at least once, calling a macro from global.mpt should work.

    Good luck!
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    • Marked as answer by WLID1966 Thursday, May 8, 2014 8:10 PM
    Thursday, May 8, 2014 4:20 PM
    Moderator
  • Hi Barbara,

    Thanks a lot for your help!

    I did not succeeded in creating a reference to Global.mpt (I'm using Project 2013) My system is uncooperative :(

    The manual option ends with "Invalid procedure call or argument"

    A direct selection of "ProjectGLobal" in the Reference dialog ends with the same error: "Invalid procedure call or argument"

    The SetReferenceGlobalMPT proc generate an error : 48 "Error in loading DLL"

    What in my system can cause so much trouble?

    Thanks again

    Thursday, May 8, 2014 5:52 PM
  • Barbara,

    Definitely, your VBA macro works fine... on my old MS Project 2003 and Windows XP 32 bits.

    That's my MS Project 2013 on Windows Server 2012 64 bits which is problematic. I'll try to find if these features may be efficient in this environment.

    Thanks a lot

    Thursday, May 8, 2014 8:17 PM
  • Quite possibly your Global.mpt file is in a different location. So you need to find the full path for the Global.mpt file for each user, or create one on a shared folder on your network. Then try:

    Sub TestMe()
    Const FullPath = "C:\Users\Admin Boss\AppData\Roaming\Microsoft\MS Project\14\1033\Global.MPT"
        ActiveProject.VBProject.References.AddFromFile FullPath
    End Sub
    Note that the code needs error handling if running a second time and the reference already exists.


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz


    Thursday, May 8, 2014 8:42 PM
    Moderator
  • Hi,

    ok, I tested with english Project 2010 on Windows 8. Now tried with Project 2013. Funny enough, I can reproduce your message when adding die German global file when running Project in German. However, adding path of English version does work when running in English, I see Global in list of references. But I get an error "File format not longer supported" when closing reference dialog. I will dig into deeper on Sunday and let you know.

    Sorry for now!
    Barbara

    P.s.: You did replace "14" in path of Rod and me to "15", didn't you?


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    Friday, May 9, 2014 4:08 AM
    Moderator
  • Hi,

    <<You did replace "14" in path of Rod and me to "15", didn't you?>>

    Yes, I did!

    I don't have Project 2010 on this server.

    Thanks for your help !

    Friday, May 9, 2014 8:41 AM
  • Hi,

    reproduced issue on Windows Server 2012 Standard.

    @Rod: Are you able to set reference for Project 2013? If so, what OS are you running?

    Regards
    Barbara


    To increase the value of this forum, please mark the replies that helped to solve your issue as answer. If you find answers to questions from other forum participants to be helpful, please mark them as helpful. Your participation will help others to find an appropriate solution faster. Thanks for your support!

    Friday, May 9, 2014 8:47 AM
    Moderator