none
VBA in project to protect task with actual work RRS feed

  • Question

  • hello :

           now i have a question about VBA in project. i offen delete tasks with actual work, so i think can i use VBA to protect tasks with actual work?

          thanks!


    peardong

    Thursday, March 29, 2012 7:51 AM

Answers

  • Hello Rod Gill!

            thanks !

            Now i create a VBA program,the code is:

             ClassModule---- EventClassBeforeDeleteModule

    Public WithEvents App As Application
    
    Private Sub App_ProjectBeforeTaskDelete(ByVal t As Task, Cancel As Boolean)
        If t.ActualWork > 0 Then
            MsgBox t.Name & "has actual work"
            Cancel = True
        Else
            t.Delete
        End If
       
    End Sub
    
    

    module

    Option Explicit
    
    Dim X As New EventClassBeforeDeleteModule
    
    Sub Initialize_App_Delete()
    
        Set X.App = MSProject.Application
     
    
    End Sub
    now i run the micro then it works. and now i can not delete task with actual work.

    but now a new question: it doesn't work when i open project again. it works when i run the micro again. how can it work always?

    thanks!


    peardong

    Thursday, March 29, 2012 3:47 PM
  • hello

          i got the answer of the question。if want to run zhe vba program, i need set "ThisProject (Global.MPT)" open event.

           then when the project open, the vba will run.


    peardong

    Saturday, March 31, 2012 6:47 AM

All replies

  • You can create a BeforeDelete event that can do that. This is a task event which is reasonably hard to set up.

    When you delete a task with actual work, Project should prompt you with an are you sure dialog. So your easiest solution is to make this a training issue.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management

    Thursday, March 29, 2012 8:00 AM
    Moderator
  • Hello Rod Gill!

            thanks !

            Now i create a VBA program,the code is:

             ClassModule---- EventClassBeforeDeleteModule

    Public WithEvents App As Application
    
    Private Sub App_ProjectBeforeTaskDelete(ByVal t As Task, Cancel As Boolean)
        If t.ActualWork > 0 Then
            MsgBox t.Name & "has actual work"
            Cancel = True
        Else
            t.Delete
        End If
       
    End Sub
    
    

    module

    Option Explicit
    
    Dim X As New EventClassBeforeDeleteModule
    
    Sub Initialize_App_Delete()
    
        Set X.App = MSProject.Application
     
    
    End Sub
    now i run the micro then it works. and now i can not delete task with actual work.

    but now a new question: it doesn't work when i open project again. it works when i run the micro again. how can it work always?

    thanks!


    peardong

    Thursday, March 29, 2012 3:47 PM
  • hello

          i got the answer of the question。if want to run zhe vba program, i need set "ThisProject (Global.MPT)" open event.

           then when the project open, the vba will run.


    peardong

    Saturday, March 31, 2012 6:47 AM