0
votes

I've modified the code for UN-protecting Excel VBA Project to work with Microsoft Project from the link below.

Unprotect VBProject from VB code

But in MS Project there is always a Global.mpt(my code runs from here) and when the below line executes

projAp.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute

it always opens the VBA Project Properties of the Global.mpt file.

How do I select my Project Plan's VBA Project Properties? Is there a Windows API function that would let me choose the second VBA Project Shown in the screen host. Launching the FindControl command after selecting the proejct should launch it corresponding VBA Project Properties(Manually tried this).

Screen Shot of Project VBA

2
I am not sure I understand but I think you need to iterate through VBProjects to get references to the right one since you are qualifying your projAp as VBIDE.Project possiblyuser2140173
@mehow I tried that now: debug.Print projAp.ActiveProject.VBProject.VBE.VBProjects.Item(1).FileName C:\Users\IBM_ADMIN\AppData\Roaming\Microsoft\MS Project\14\1033\Global.mpt debug.Print projAp.ActiveProject.VBProject.VBE.VBProjects.Item(2).FileName C:\Users\IBM_ADMIN\Desktop\Project Plan v2.46.mpt projAp.VBE.VBProjects.Item(2).VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute Even if I explicitly select the second VBAProject as in code snippet above the first VBA Project Properties only opens again.RamY

2 Answers

1
votes

The trick is to switch over to the Project pane and "type" the first letter of the project name; I suggest you change it from the default VBAProject if possible.

SendKeys "%{F11}"
SendKeys "^r"
SendKeys "V"
DoEvents
VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
0
votes

projAp.VBE.CommandBars(1).

Your code is always working with the application object, so is always looking in the Global.mpt file. try:

ActiveProject.VBProject.VBE.CommandBars(1)

It should return only items for the project.