I have Excel VBA code that relies on the Microsoft Office Project Object Library 16.0 to run. It executes perfectly when the library is manually selected (by going to Tools -> References and checking it off). I don't want my users to have to select the project library - in fact I'd rather they stay away from the VBA editors completely - so I tried adding it inline using its GUID.
For the library GUID, I found {A7107640-94DF-1068-855E-00DD01075445} with Major and Minor numbers 4 and 9, respectively. I then tried running the following without the library selected:
Sub testReference()
ThisWorkbook.VBProject.References.AddFromGuid GUID:="{A7107640-94DF-1068-
855E-00DD01075445}", Major:=4, Minor:=9
Dim MP_App As MSProject.Application
Set MP_App = CreateObject("Msproject.Application")
Dim MP_Project As MSProject.Project
MP_App.Visible = True
MP_App.FileOpenEx Name:="C:\Users\Adam Wertheimer\Desktop\testProjectFile.mpp"
End Sub
except it flags the line
Dim MP_App As MSProject.Application
with the compile error "User-defined type not defined", so either the library didn't get added properly or there is something else I'm missing. I really don't want to have all users have to check off the project library manually, but if I have to then so be it. Any advice/help would be greatly appreciated.
Dim MP_App As object
for late binding. The CreateObject will take care of the rest. If you wanted to add a late-bound dictionary class, you wouldn't import the library, just dim as object and createobject. – user4039065