Hi Everyone,
I'm hoping you could help. I'd like to create an Outlook calendar meeting request each time a spreadsheet is saved, the meeting requests needs to be added to a shared mailbox so that all users that have access then see the meeting invite.
So far I have this setup so it adds an entry to my personal calendar but that's not quite what I want.
I'm no vba expert by a long shot. Any help is greatly appreciated.
Code below, thanks.
I'm hoping you could help. I'd like to create an Outlook calendar meeting request each time a spreadsheet is saved, the meeting requests needs to be added to a shared mailbox so that all users that have access then see the meeting invite.
So far I have this setup so it adds an entry to my personal calendar but that's not quite what I want.
I'm no vba expert by a long shot. Any help is greatly appreciated.
Code below, thanks.
VBA Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("2021") 'define your sheet!
Dim olApp As Object 'create outlook application
Set olApp = CreateObject("Outlook.Application")
Dim olNS As Object 'get namespace
Set olNS = olApp.GetNamespace("MAPI")
'define constants if using late binding
Const olFolderCalendar As Long = 9
Const olAppointmentItem As Long = 1
Dim olRecItems As Object 'get all appointments
Set olRecItems = olNS.GetDefaultFolder(olFolderCalendar)
Dim strFilter As String 'filter for appointments
Dim olFilterRecItems As Object 'filtered appointments
Dim iRow As Long
iRow = 3
Do Until Trim$(ws.Cells(iRow, 3).Value) = vbNullString
'filter appointments for subject
strFilter = "[Subject] = '" & Trim$(ws.Cells(iRow, 4).Value) & "'"
Set olFilterRecItems = olRecItems.Items.Restrict(strFilter)
If olFilterRecItems.Count = 0 Then 'if subject does not exist
With olApp.CreateItem(olAppointmentItem)
.Subject = ws.Cells(iRow, 4).Value
.Start = ws.Cells(iRow, 3).Value
.AllDayEvent = True
.BusyStatus = 5
.ReminderSet = True
.Save
End With
ws.Cells(iRow, 3).Interior.ColorIndex = 50
End If
iRow = iRow + 1
Loop
End Sub