Triggering code when a new all-day event is entered

  • Thread starter Thread starter James Martin
  • Start date Start date
J

James Martin

Hello,

I was hoping someone could help me by telling me how I can get Outlook to
execute code whenever a new all-day event is entered. I've been snooping
around and can't quite figure it out. I've found various articles that say
to:

1. Declare an object variable WithEvents in the ThisOutlookSession module.

2. Initialize the declared object in the Application_Startup procedure.

3. Write code in the ThisOutlookSession module to respond to the declared
object's events.

My problem is with the syntax of each of those things. If it's not too much
trouble could someone provide me with an example of what code I'd actually
have to use for each of those three things in order to fire an event
whenever a new all-day event is entered?

That would be greatly appreciated!

Thanks in advance.

James
 
Hi James,

this little sample executes if an Item is added to the default calendar:

'<DieseOutlookSitzung>
Private WithEvents Items As Outlook.Items

Public Sub Application_Startup()
Dim oFld As Outlook.MAPIFolder
Set oFld = Application.Session.GetDefaultFolder(olFolderCalendar)
If Not oFld Is Nothing Then
Set Items = oFld.Items
End If
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
Dim oAppt As Outlook.AppointmentItem

If TypeOf Item Is Outlook.AppointmentItem Then
Set oAppt = Item
If oAppt.AllDayEvent Then
' here your code goes
End If
End If
End Sub
'</DieseOutlookSitzung>
 
Hi Miachael,

That's perfect!

Thanks a ton for the help. You've saved me hours of frustration!

James
 
Back
Top