MSProject Open event

Add-in Express™ Support Service
That's what is more important than anything else

MSProject Open event
 
Drew Heald




Posts: 9
Joined: 2006-07-14
Does anyone know how to hook into the Open event of the MSProject.Project object when using ADX? I have tried adding event handlers in the New sub of ADX's AddinModule but nothing is happening.

Posted 19 Jul, 2006 10:48:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Drew.

What version of MS Project do you use?
Posted 19 Jul, 2006 11:14:11 Top
Drew Heald




Posts: 9
Joined: 2006-07-14
Hi Sergey,

Currently 2003 but our intention is to write versions for XP and 2000 too
Posted 19 Jul, 2006 11:41:24 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Drew, you need to use the ADXProjectAppEvents component to add MS Project events to the code.
Posted 19 Jul, 2006 11:56:34 Top
Drew Heald




Posts: 9
Joined: 2006-07-14
Hi Sergey,

Yes, I have done that. (I've already written code in MSProject's ProjectBeforeSave event - that code is working OK.)

The problem is that AFAIK there is no ProjectOpen (or equivalent) event on MSProject's application object. However, there is an 'Open' event on MSProject's project object. It is that event I am trying to access using VB.NET's AddHandler construct. This approach worked in a previous version of my add-in written without ADX but it doesn't work in the version with ADX. I guess I'm missing something.

Any ideas?
Posted 20 Jul, 2006 04:07:51 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Drew.

It is strange but I can't find the ProjectOpen event in the MS Project application object. Could you please send me a bit of code that shows on how you used this event in the old version of your add-in?
Posted 20 Jul, 2006 14:07:20 Top
Drew Heald




Posts: 9
Joined: 2006-07-14
Hi Sergey,

That's right. MSProject is different from the rest of the Office suite (hard to believe, I know). There is no ProjectOpen event on MSProject's application object - there is an Open event on MSProject's project object.

In my old version, in the Extensibility.IDTExtensibility2.OnConnection event, once I had determined that the Office application was MSProject I had the following:

Dim objProject As Microsoft.Office.Interop.MSProject.Project

For Each objProject In mobjMSProjectApp.Projects
     AddHandler objProject.Open, AddressOf ProjectOpened
Next 'objProject

where mobjMSProjectApp was the MSProject application object.
'ProjectOpened' was the subroutine containing the event handling code.

I have tried something similar in the 'New' subroutine of ADX's AddinModule class, i.e.


'set up the required event handlers for MSProject
Dim objMSProjectApp As MSProject.Application
Dim objProject As MSProject.Project

Try
     objMSProjectApp = CType(HostApplication, MSProject.Application)
Catch
     objMSProjectApp = Nothing
End Try

If Not objMSProjectApp Is Nothing Then
     For Each objProject In objMSProjectApp.Projects
          AddHandler objProject.Open, AddressOf ProjectOpened
     Next 'objProject
End If


The first one works, the second one doesn't.
I also tried:
objMSProjectApp = CType(HostApplication, MSProject._MSProject)
in the Try... Catch but that didn't work either.

Suggestions?
Posted 21 Jul, 2006 04:46:03 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Drew.

You should use the AddinInitialize or AddinStartupComplete event handlers because the HostApplication property is not initialized in the addinmodule constructor.
Posted 21 Jul, 2006 13:26:32 Top
Drew Heald




Posts: 9
Joined: 2006-07-14
Thanks Sergey.

I hadn't noticed that set of events (oops). I have now gotten it working. In case anyone is interested, here's what I did in the AddinModule's AddinStartupComplete event:


Dim objMSProjectApp As MSProject.Application
Dim objProject As MSProject.Project

If HostType = AddinExpress.MSO.ADXOfficeHostApp.ohaProject Then
	objMSProjectApp = CType(HostApplication, MSProject.Application)
	If Not objMSProjectApp Is Nothing Then
		For Each objProject In objMSProjectApp.Projects
                	AddHandler objProject.Open, AddressOf ProjectOpened
                Next 'objProject
	End If
End If


The code in the 'ProjectOpened' subroutine now runs quite happily when an MSProject application is fired up.

Drew.
Posted 24 Jul, 2006 05:07:41 Top