COM Add-in Document Events

M

Mark Durrenberger

Hi all, I'm a MS Project Developer but no one on the MSProject news groups
seems to be able to help and Outlook is the most active add-in group so I'm
hoping to reach someone with some experience on my issue.
Thanks in advance,
Mark


In Project there are several "Document" level events like Open (and
Activate, BeforeClose, BeforePrint,BeforeSave, Calculate,Deactivate). I am
trying to trap the Open event.
I'm using VB6 (SP6) and IDTExtensibility2

Has anyone been successful at trapping the On_open (or any document level
event in a com add-in. I'm having a heck of a time getting this to work.
Specifically I'm working with MS Project, but I'm hoping the setup is
similar to other Office products.

I created a class
=====
Option Explicit
Private WithEvents ProjEvents As MSProject.Project

Private Sub ProjEvents_Open(ByVal pj As MSProject.Project)
MsgBox "open event", vbOKOnly
End Sub
=====
I know the class is right because when I click on the Procedure window I'm
presented with the
Activate, BeforeClose, BeforePrint,BeforeSave, Calculate,Deactivate, Open
procedures.
I think these are called "Document level" events (as opposed to "Application
level events")

What I don't know how to do is tie these events to the instance of Project.
It does not appear to work the same as application level events.

I have searched high and low for the solution to this problem. I even tried
code that is supposed to work with doc level events in a Word COM Add-in.

Any help appreciated,
Thanks,
Mark

BTW, if you want to implement application level events in a COM add in for
MSProject, follow the instructions below.

Application level events are done this way:
Create your class. I'll call it MyClass
in MyClass put
===== Class MyClass ====
Public WithEvents AppEvents as MSProject.Application
along with your event code like

Private Sub AppEvents_ProjectBeforeTaskChange(ByVal tsk As MSProject.Task, _
ByVal Field As PjField, _
ByVal NewVal As Variant, _
Cancel As Boolean)
'do stuff on change
end sub

In a regular module, create a public object variable
Public oAppEvents as MyClass

Somewhere in your code (I do this in the IDTExtensibility2_OnConnection
code) Store the current instance of Project passed to the Add-In from
the OnConnection code as "Application"

set gblAppInstance = Application
Set oAppEvents = New MyClass
Set oAppEvents.MyClass = gblAppInstance ' turn on events by tying the
add-in class to the current instance of Project.

now any time you change something in a Project document, the on-change event
fires and you can process the change (for example, I have a field that is in
units of hours, if the user enters "2.5d" the value displayed in the field
is 2.5*activeproject.hoursperday)

--
_________________________________________________________
Mark Durrenberger, PMP
Principal, Oak Associates, Inc, www.oakinc.com
"Advancing the Theory and Practice of Project Management"
________________________________________________________

The nicest thing about NOT planning is that failure
comes as a complete surprise and is not preceded by
a period of worry and depression.

- Sir John Harvey-Jones
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top