Log in

View Full Version : VBA code when an item is created



ID015
04-14-2016, 06:47 AM
does anyone know if it's possible to trigger some VBA code every time a certain item type is created?
For example, every time a meeting invite is created, do x, y, z.

thank you

gmayor
04-14-2016, 10:39 PM
You could investigate Outlook Events, but if you are creating a meeting, then why not use the macro to create the meeting and include the process you wish to add e.g.



Option Explicit
'Graham Mayor - www.gmayor.com
Sub CreateMeeting(strSubject As String, _
strLocation As String, _
strDate As String, _
strTime As String, _
iMinutes As Integer, _
strName1 As String, _
strName2 As String, _
strBodyText As String)

Dim olItem As AppointmentItem
Dim rRequiredAttendee As Recipient
Dim rOptionalAttendee As Recipient
Dim olInsp As Outlook.Inspector
Dim wdDoc As Object
Dim oRng As Object

Set olItem = CreateItem(olAppointmentItem)
With olItem
.MeetingStatus = olMeeting
.Subject = strSubject
.Location = strLocation
.start = strDate & Chr(32) & strTime ' & strAMPM
.Duration = iMinutes
Set rRequiredAttendee = .Recipients.Add(strName1)
rRequiredAttendee.Type = olRequired
Set rOptionalAttendee = .Recipients.Add(strName2)
rOptionalAttendee.Type = olOptional
.Display
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
Set oRng = wdDoc.Range
oRng.Text = strBodyText
End With
Set olItem = Nothing
Set rRequiredAttendee = Nothing
Set rOptionalAttendee = Nothing
Set olInsp = Nothing
Set wdDoc = Nothing
Set oRng = Nothing
lbl_Exit:
Exit Sub
End Sub

Sub TestMeeting()
CreateMeeting "Strategy Meeting", "Conference Room", "04/16/2014", "14:00", 30, "John Smith", "Bill Jones", "Meeting to discuss planning for Christmas holidays"
lbl_Exit:
Exit Sub
End Sub