Calendar (.ics) Sharing in Outlook Add-in using VBA code

Calendar (.ics) Sharing in Outlook Add-in using VBA code

Calendar Share

Sometime you may in need where you would like to share your calendar with others to sync. Outlook exposes CalendarSharing object which holds reference of your calendar. Further this object can be used to set various properties to customize details before sharing your calendar with others.

Code example

Public Sub ExportCalendar()

    'Outlook application object declaration
    Dim oApp As Outlook.Application
    'bind current outlook instance
    Set oApp = GetObject("", "Outlook.Application")
    'Bind namespace
    Dim oNameSpace As Outlook.Namespace
    Set oNameSpace = oApp.GetNamespace("MAPI")
    'Bind all calendar in outlook
    Dim oCalFolder As Folder
    Set oCalFolder = oNameSpace.GetDefaultFolder(olFolderCalendar)
    'Export calendar
    Dim oCalSharing As CalendarSharing
    Set oCalSharing = oCalFolder.GetCalendarExporter
    'set sharing object to export entire calendar
    'Complete calendar
    oCalSharing.CalendarDetail = olFullDetails
    'oCalSharing.CalendarDetail =olFreeBusyAndSubject
    'oCalSharing.CalendarDetail =olFreeBusyOnly
    oCalSharing.IncludeAttachments = True
    oCalSharing.IncludePrivateDetails = True
    oCalSharing.IncludeWholeCalendar = True
    'Specify date
    oCalSharing.StartDate = CDate(Format(Now, "dd/mm/yyyy"))
    'Save calendar to share
    oCalSharing.SaveAsICal "C:\Users\Download\myCal.ics"
    If Not oCalFolder Is Nothing Then
        Set oCalFolder = Nothing
    End If
    If Not oCalSharing Is Nothing Then
        Set oCalSharing = Nothing
    End If
    If Not oApp Is Nothing Then
        Set oApp = nohting
    End If
End Sub


The above code offers capability to extract your calendar and customize various details like StartDate from which you would like to share your calendar from. Share free schedule or busy schedule etc. Finally we call SaveAsICal method which will save calendar with “.ics” extension which you can share with anyone.

Next >> Print attachments from selected emails in outlook using VBA

Leave a Reply

Your email address will not be published. Required fields are marked *