none
Can I create a read-only calendar folder? RRS feed

  • Question

  • I want to programmatically create a calendar folder, add a number of appointments, then display it as an overlay under the user's default calendar. How can I make the calendar read-only so that any appointments always go to the default calendar?

    Thanks.


    Mike VE

    Saturday, March 31, 2018 7:35 AM

Answers

  • Hi Mike VE,

    You had mentioned that,"I want to programmatically create a calendar folder, add a number of appointments, then display it as an overlay under the user's default calendar."

    Try to refer example below.

    Private Sub CreateCompanyEventsFolder() 
     Dim objNamespace As NameSpace 
     Dim objCalendar As Folder 
     Dim objFolder As Folder 
    
     Dim objPane As NavigationPane 
     Dim objModule As CalendarModule 
     Dim objGroup As NavigationGroup 
     Dim objNavFolder As NavigationFolder 
    
     On Error GoTo ErrRoutine 
    
     ' First, retrieve the default calendar folder. 
     Set objNamespace = Application.GetNamespace("MAPI") 
     Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) 
    
     ' Create a new calendar folder named "Company Events". 
     Set objFolder = objCalendar.Folders.Add("Company Events", olFolderCalendar) 
    
     ' Get the NavigationPane object for the 
     ' currently displayed Explorer object. 
     Set objPane = Application.ActiveExplorer.NavigationPane 
    
     ' Get the calendar module from the Navigation Pane. 
     Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) 
    
     ' Get the "My Calendars" navigation group from the 
     ' calendar module. 
     With objModule.NavigationGroups 
     Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) 
     End With 
    
     ' Add a new navigation folder for the "Company Events" 
     ' folder in the "My Calendars" navigation group. 
     Set objNavFolder = objGroup.NavigationFolders.Add(objFolder) 
    
     ' Set the navigation folder to be displayed in overlay mode 
     ' by default. The IsSelected property can't be set to True 
     ' unless the CalendarModule object is the current module 
     ' displayed in the Navigation Pane. 
     Set objPane.CurrentModule = objModule 
     objNavFolder.IsSelected = True 
     objNavFolder.IsSideBySide = False 
    
    EndRoutine: 
     On Error GoTo 0 
    
     Set objNavFolder = Nothing 
     Set objFolder = Nothing 
     Set objGroup = Nothing 
     Set objModule = Nothing 
     Set objPane = Nothing 
     Set objNamespace = Nothing 
    
     Exit Sub 
    
    ErrRoutine: 
     MsgBox Err.Number &; " - " &; Err.Description, _ 
     vbOKOnly Or vbCritical, _ 
     "CreateCompanyEventsFolder" 
    End Sub

    Reference:

    Add a Custom Folder to a Group and Display it in Overlay Mode by Default

    Refer example below to add appointment.

    Sub ApptToOtherCal()
    
        Dim olApp As Outlook.Application
        Dim olAppt As Outlook.AppointmentItem
        Dim olFldr As Outlook.MAPIFolder
        
        Set olApp = New Outlook.Application
        Set olFldr = olApp.GetNamespace(“MAPI”).Folders(“Personal Folders”) _
            .Folders(“OtherCal”)
            
        Set olAppt = olFldr.Items.Add
        
        With olAppt
            .Start = Now + TimeSerial(1, 0, 0)
            .End = Now + TimeSerial(2, 0, 0)
            .Subject = “Post to blog”
            .Save
        End With
        
        Set olApp = Nothing
        
    End Sub

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Mike VE Monday, April 2, 2018 4:11 PM
    • Unmarked as answer by Mike VE Monday, April 2, 2018 4:11 PM
    • Marked as answer by Mike VE Monday, April 2, 2018 4:12 PM
    Monday, April 2, 2018 6:54 AM
    Moderator

All replies

  • Hi Mike VE,

    You had mentioned that,"I want to programmatically create a calendar folder, add a number of appointments, then display it as an overlay under the user's default calendar."

    Try to refer example below.

    Private Sub CreateCompanyEventsFolder() 
     Dim objNamespace As NameSpace 
     Dim objCalendar As Folder 
     Dim objFolder As Folder 
    
     Dim objPane As NavigationPane 
     Dim objModule As CalendarModule 
     Dim objGroup As NavigationGroup 
     Dim objNavFolder As NavigationFolder 
    
     On Error GoTo ErrRoutine 
    
     ' First, retrieve the default calendar folder. 
     Set objNamespace = Application.GetNamespace("MAPI") 
     Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) 
    
     ' Create a new calendar folder named "Company Events". 
     Set objFolder = objCalendar.Folders.Add("Company Events", olFolderCalendar) 
    
     ' Get the NavigationPane object for the 
     ' currently displayed Explorer object. 
     Set objPane = Application.ActiveExplorer.NavigationPane 
    
     ' Get the calendar module from the Navigation Pane. 
     Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) 
    
     ' Get the "My Calendars" navigation group from the 
     ' calendar module. 
     With objModule.NavigationGroups 
     Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) 
     End With 
    
     ' Add a new navigation folder for the "Company Events" 
     ' folder in the "My Calendars" navigation group. 
     Set objNavFolder = objGroup.NavigationFolders.Add(objFolder) 
    
     ' Set the navigation folder to be displayed in overlay mode 
     ' by default. The IsSelected property can't be set to True 
     ' unless the CalendarModule object is the current module 
     ' displayed in the Navigation Pane. 
     Set objPane.CurrentModule = objModule 
     objNavFolder.IsSelected = True 
     objNavFolder.IsSideBySide = False 
    
    EndRoutine: 
     On Error GoTo 0 
    
     Set objNavFolder = Nothing 
     Set objFolder = Nothing 
     Set objGroup = Nothing 
     Set objModule = Nothing 
     Set objPane = Nothing 
     Set objNamespace = Nothing 
    
     Exit Sub 
    
    ErrRoutine: 
     MsgBox Err.Number &; " - " &; Err.Description, _ 
     vbOKOnly Or vbCritical, _ 
     "CreateCompanyEventsFolder" 
    End Sub

    Reference:

    Add a Custom Folder to a Group and Display it in Overlay Mode by Default

    Refer example below to add appointment.

    Sub ApptToOtherCal()
    
        Dim olApp As Outlook.Application
        Dim olAppt As Outlook.AppointmentItem
        Dim olFldr As Outlook.MAPIFolder
        
        Set olApp = New Outlook.Application
        Set olFldr = olApp.GetNamespace(“MAPI”).Folders(“Personal Folders”) _
            .Folders(“OtherCal”)
            
        Set olAppt = olFldr.Items.Add
        
        With olAppt
            .Start = Now + TimeSerial(1, 0, 0)
            .End = Now + TimeSerial(2, 0, 0)
            .Subject = “Post to blog”
            .Save
        End With
        
        Set olApp = Nothing
        
    End Sub

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Mike VE Monday, April 2, 2018 4:11 PM
    • Unmarked as answer by Mike VE Monday, April 2, 2018 4:11 PM
    • Marked as answer by Mike VE Monday, April 2, 2018 4:12 PM
    Monday, April 2, 2018 6:54 AM
    Moderator
  • Thanks Deepak, that's just what I needed.

    I haven't found a way to make the folder read-only once I have programmatically created the necessary appointments.


    Mike VE

    Monday, April 2, 2018 4:13 PM