Stop! Don’t delete approved tasks


In my earliest post, you learnt about how to use Calculate Event procedure in the Project object to color tasks with no dependencies set. The events of Project are available for any open project – reference http://msdn.microsoft.com/en-us/library/office/dn217671(v=office.15).aspx

You have a more powerful object called Application. It represents the entire Project application. To write event procedures for the Application object, you must follow a new approach.

Let’s take an example to illustrate Application object’s event procedure. As a best practice, it is advisable not to delete baseline tasks since you will lose the evidence and will have incorrect variance. It is hence recommended to Inactivate the task (see this blog about the benefits).

Design and Build tasks is approved and Test task is inserted later.

After deleting Build task, you lost the proof that Build was part of your plan

The following steps will guide you how to create event handler before a task is deleted

1. Click View tab. Click Macros dropdown and select Visual Basic
image12.png?w=640

2. In the Visual Basic Editor, on the option menu for VBAProject, choose Insert, and then choose Class Module to create a class named Class1.

3. You can rename the class module in the Properties pane. In the following examples, the class is named Events.

4. You must create a new object using the WithEvents keyword in a class module
Public WithEvents App As Application
5. Now change the object and procedure to "App" and "ProjectBeforeTaskDelete". ProjectBeforeTaskDelete event will be fired for every task that is deleted.

6. Within this sub-routine include the below code

7. You need to bind the current Application object to the App object declared in the class to fire the events. Open the ThisProject module and paste the below code. This code declares an object X of type Events (the class module we created earlier), and sets the current Application object to the App object of Events class module

The code displays the message "Dont’ delete baseline task. Instead Inactivate the task" and cancels the delete action if the Baseline Start of the task deleted is set.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s