Compartilhar via


CurrentView Property

Returns or sets a View object (for the MAPIFolder object) or Variant (for the Explorer object) representing the current view. Read-only for the MAPIFolder object. Read/write for the Explorer object.

expression**.CurrentView**

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

Remarks

When this property is set, two events occur: BeforeViewSwitch occurs before the actual view change takes place and can be used to cancel the change and ViewSwitch takes place after the change is effective.

Example

The following Visual Basic for Applications (VBA) example sets the current view in the active explorer to messages if the Inbox is displayed.

Sub ChangeCurrentView()
    Dim myOlApp As New Outlook.Application
    Dim myOlExp As Outlook.Explorer
    Set myOlExp = myOlApp.ActiveExplorer
    If myOlExp.CurrentFolder = "Inbox" Then
        myOlExp.CurrentView = "Messages"
    End If
End Sub

If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object. This example shows how to perform the same task using VBScript code.

Sub CommandButton1_Click()
   Application.ActiveExplorer.CurrentView = "Messages"
End Sub

The following VBA example displays the current view of the Inbox folder.

Sub TestMAPIFolderCurrentView()
    Dim nsp As Outlook.NameSpace
    Dim mpFolder As Outlook.MAPIFolder
    Dim vw As Outlook.View
    Dim strView As String
    
    Set nsp = Application.Session
    Set mpFolder = nsp.GetDefaultFolder(olFolderInbox)
    Set vw = mpFolder.CurrentView
    MsgBox "The Current View is: " & vw.Name
    
End Sub

Applies to | Explorer Object | MAPIFolder Object