Check if a code module exists in the Global.MPT instead of the ActiveProject does not work

BVOPP

Board Regular
Joined
Feb 9, 2015
Messages
57
In the internet I found an excel version and changed it for MS Project. The Set Module = ActiveProject.VBProject.VBComponents(name).CodeModule does work but the Set Module = GlobalMPT.VBProject.VBComponents(name).CodeModule does not give an error but it does not work either....
Any idea??

VBA Code:
Sub tester()

    Debug.Print Is_Module_Loaded("Module1")

End Sub


Public Function Is_Module_Loaded(name As String) As Boolean

    Dim Module As Object

    On Error Resume Next
    'Set Module = ActiveProject.VBProject.VBComponents(name).CodeModule
    Set Module = GlobalMPT.VBProject.VBComponents(name).CodeModule
    On Error GoTo 0

    Is_Module_Loaded = Not Module Is Nothing

    If Not Is_Module_Loaded Then
        MsgBox ("MODULE: " & name & " is not installed please add")
    Else
        MsgBox ("MODULE: " & name & " is already installed")
    End If

End Function
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
GlobalMPT is a variable. Did you previously (outside of the function) declare this variable and assign Global.mpt to it?

Artik
 
Upvote 0
No I did not do that... In stead of GlobalMPT i also tested with Global.mpt but that does not work neither.
Tried several ways to assign but none works.
 
Upvote 0
Does this work?
VBA Code:
Sub tester()
    Debug.Print Is_Module_Loaded("Module1")
End Sub


Public Function Is_Module_Loaded(name As String) As Boolean
    Dim GlobalMPT As Object
    Dim Module As Object

    Set GlobalMPT = Application.GlobalTemplate.VBProject
    
    On Error Resume Next
    Set Module = GlobalMPT.VBComponents(name).CodeModule
    On Error GoTo 0

    Is_Module_Loaded = Not Module Is Nothing

'    If Not Is_Module_Loaded Then
'        MsgBox ("MODULE: " & name & " is not installed please add")
'    Else
'        MsgBox ("MODULE: " & name & " is already installed")
'    End If

End Function
Artik
 
Upvote 0
1. Are you running this test code from within MS Project or another application, such as Excel?
2. Do you have “Programmatic access to VBA project” enabled in the program options?

Unfortunately, this application is completely unknown to me. I have spoken with Copilot and it alleges that the reference is correct:
VBA Code:
Set GlobalMPT = Application.GlobalTemplate.VBProjectCodeModule

Artik
 
Upvote 0
Hi @Artik
1. Running in MS Project
2. Access Trust Center Settings: Go to File → Options. Navigate to the Trust Center tab, then click on Trust Center Settings. Macro Settings: In the Trust Center window, select Macro Settings. Check the option: Trust access to the VBA project object model. But this option is not available at all, see attachment added...

Schermafbeelding 2024-12-11 112217.png


In Application there is no .GlobalTemplate Only
.GlobalBaseCalendars
.GlobalOutlineCodes
.GlobalReports
.GlobalResourceFilters
.GlobalResourceTables
.GlobalTaskFilters
.GlobalTaskTables
.GlobalViews
.GlobalViewsCombibation
.GlobalViewsSingle
 
Upvote 0
Trust access to the VBA project object model
Try under Macro Security in the Code section on the Developer tab, if not is it a company computer?

1733913721582.png

T
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,549
Messages
6,185,582
Members
453,307
Latest member
addydata

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top