DeselectFolder Method

Microsoft Outlook Visual Basic

DeselectFolder Method

If the explorer is currently displaying the Calendar folder simultaneously with another Calendar folder, the specified folder will be closed. Returns Nothing.

expression.DeselectFolder(MAPIFolder)

expression    Required. An expression that returns one of the objects in the Applies To list.

MAPIFolder    Required. The MAPIFolder object representing the Calendar folder to be closed in the explorer.

Remarks

The DeselectFolder method works only with Calendar folders.

If the folder is the only folder that is currently displayed in the explorer, the folder is not closed. Instead, Outlook will display an error.

Example

This Microsoft Visual Basic for Applications (VBA) example closes a shared calendar that is displayed simultaneously with the current user's default calendar folder. To run this example without errors, replace Dan Wilson with a valid recipient name whose calendar is shared and whose calendar you have permissions to view. You also need to display the shared calendar in Shared Calendar view. To do this, you can run the DispCalendars procedure before running the CloseSharedCalendar procedure.

    Sub CloseSharedCalendar()
    Dim myOlApp As Outlook.Application
    Dim myNms As Outlook.NameSpace
    
    Dim myRecipient As Outlook.Recipient
    Dim myExplorer As Outlook.Explorer
    Dim SharedFolder As Outlook.MAPIFolder
    
    Set myOlApp = CreateObject("Outlook.Application")
        
    Set myNms = myOlApp.GetNamespace("MAPI")
    Set myExplorer = myOlApp.ActiveExplorer
    Set myRecipient = myNms.CreateRecipient("Dan Wilson")
    Set SharedFolder = myNms.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
    If myExplorer.IsFolderSelected(SharedFolder) = True Then
        myExplorer.DeselectFolder SharedFolder
    End If
End Sub
  
    Sub DispCalendars()
    Dim myOlApp As Outlook.Application
    Dim myNms As Outlook.NameSpace
    Dim myFolder As Outlook.MAPIFolder
    Dim myRecipient As Outlook.Recipient
    Dim myExplorer As Outlook.Explorer
    Dim SharedFolder As Outlook.MAPIFolder
    
    Set myOlApp = CreateObject("Outlook.Application")
        
    Set myNms = myOlApp.GetNamespace("MAPI")
    Set myFolder = myNms.GetDefaultFolder(olFolderCalendar)
    
    Set myExplorer = myOlApp.ActiveExplorer
    Set myExplorer.CurrentFolder = myFolder
    Set myRecipient = myNms.CreateRecipient("Dan Wilson")
    Set SharedFolder = myNms.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
    myExplorer.SelectFolder SharedFolder
End Sub