0

I have code in ThisOutlookSession module from run a macro when creating new appointment in outlook:

Private WithEvents appt As AppointmentItem
Private WithEvents objinspectors As Outlook.Inspectors

Private Sub Application_Startup()
    Set objinspectors = Application.Inspectors
End Sub

Private Sub objinspectors_NewInspector(ByVal Inspector As Inspector)
    If TypeName(Inspector.CurrentItem) = "AppointmentItem" Then
        Set appt = Inspector.CurrentItem
    End If
End Sub

Private Sub appt_Write(ByVal Item As Object, Cancel As Boolean)
    '---- ect
end sub

appt_Write works for the first appointment I create or modify. If I create a second appointment nothing happens.

I found the sub objinspectors_NewInspector does not start anymore.

I have no END command in my code. To run the code again I have to launch Application_Startup.

What should I do to make the macro work all time?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Massimo Griffani
  • 767
  • 8
  • 18

1 Answers1

0

rerun same code as Application_Startup() each time through

Private Sub appt_Write(ByVal Item As Object, Cancel As Boolean)
    '---- etc

    Set objinspectors = Application.Inspectors 'add this line ... see what happens
End Sub
jsotola
  • 2,238
  • 1
  • 10
  • 22