M
Marguerite
I am currently working on a program with 6 project managers. There is one
plan (which I inherited). Each PM makes a local copy and uses Text5 to
identify the task to be added changed or deleted. Well, they are not
updating Text5 consistently. So I would like to set an event to identify
when a task is changed or a task is added. In reading the documentation, it
said that you had to define a new class module and class in order to "listen
for" project events.
I created a class module called EventClassModule with the following code:
Option Explicit
Option Base 1
Public WithEvents App As Application
Public WithEvents Proj As Project
Dim NewTaskIDs() As Integer
Dim NumNewTasks As Integer
Dim ProjTaskNew As Boolean
Private Sub App_ProjectTaskNew(ByVal pj As Project, ByVal ID As Long)
NumNewTasks = NumNewTasks + 1
If ProjTaskNew Then
ReDim Preserve NewTaskIDs(NumNewTasks) As Integer
Else
ReDim NewTaskIDs(NumNewTasks) As Integer
End If
NewTaskIDs(NumNewTasks) = ID
ProjTaskNew = True
End Sub
Private Sub Proj_Change(ByVal pj As Project)
Dim NewTaskID As Variant
If ProjTaskNew Then
For Each NewTaskID In NewTaskIDs
MsgBox "New Task Name: " &
ActiveProject.Tasks.UniqueID(NewTaskID).Name
ActiveProject.Tasks.UniqueID(NewTaskID).Text5 = "Add"
Next NewTaskID
NumNewTasks = 0
ProjTaskNew = False
Else
ActiveProject.Tasks.UniqueID(NewTaskID).Text5 = "Change"
End If
End Sub
Then in a program module, I created the following code:
Option Explicit
Dim X As New EventClassModule
Sub Initialize_App()
Set X.App = MSProject.Application
Set X.Proj = Application.ActiveProject
End Sub
But it doesn't work. What am I doing wrong?
Any help would be greatly appreciated.
plan (which I inherited). Each PM makes a local copy and uses Text5 to
identify the task to be added changed or deleted. Well, they are not
updating Text5 consistently. So I would like to set an event to identify
when a task is changed or a task is added. In reading the documentation, it
said that you had to define a new class module and class in order to "listen
for" project events.
I created a class module called EventClassModule with the following code:
Option Explicit
Option Base 1
Public WithEvents App As Application
Public WithEvents Proj As Project
Dim NewTaskIDs() As Integer
Dim NumNewTasks As Integer
Dim ProjTaskNew As Boolean
Private Sub App_ProjectTaskNew(ByVal pj As Project, ByVal ID As Long)
NumNewTasks = NumNewTasks + 1
If ProjTaskNew Then
ReDim Preserve NewTaskIDs(NumNewTasks) As Integer
Else
ReDim NewTaskIDs(NumNewTasks) As Integer
End If
NewTaskIDs(NumNewTasks) = ID
ProjTaskNew = True
End Sub
Private Sub Proj_Change(ByVal pj As Project)
Dim NewTaskID As Variant
If ProjTaskNew Then
For Each NewTaskID In NewTaskIDs
MsgBox "New Task Name: " &
ActiveProject.Tasks.UniqueID(NewTaskID).Name
ActiveProject.Tasks.UniqueID(NewTaskID).Text5 = "Add"
Next NewTaskID
NumNewTasks = 0
ProjTaskNew = False
Else
ActiveProject.Tasks.UniqueID(NewTaskID).Text5 = "Change"
End If
End Sub
Then in a program module, I created the following code:
Option Explicit
Dim X As New EventClassModule
Sub Initialize_App()
Set X.App = MSProject.Application
Set X.Proj = Application.ActiveProject
End Sub
But it doesn't work. What am I doing wrong?
Any help would be greatly appreciated.