如何:确定当前的 Outlook 项

URL:http://msdn.microsoft.com/zh-cn/library/ms268994(VS.80).aspx
Dim WithEvents currentExplorer As Outlook.Explorer = Nothing

    Private Sub ThisApplication_Startup(ByVal sender As Object, _
         ByVal e As System.EventArgs) Handles Me.Startup
        currentExplorer = Me.Explorers.Application.ActiveExplorer
        AddHandler currentExplorer.SelectionChange, AddressOf _
            currentExplorer_Event
    End Sub

    Public Sub currentExplorer_Event()
        Dim selectedFolder As Outlook.MAPIFolder = _
            Me.ActiveExplorer().CurrentFolder
        Dim expMessage As String = "Your current folder is " _
            & selectedFolder.Name & "." & vbCrLf
        Dim itemMessage As String = "Item is unknown."
        Try
            If Me.ActiveExplorer.Selection.Count > 0 Then
                Dim selObject As Object = Me.ActiveExplorer _
                    .Selection.Item(1)
                If (TypeOf selObject Is Outlook.MailItem) Then
                    Dim mailItem As Outlook.MailItem = _
                        TryCast(selObject, Outlook.MailItem)
                    itemMessage = "The item is an e-mail message." & _
                        " The subject is " & mailItem.Subject & "."
                        mailItem.Display(False)
                ElseIf (TypeOf selObject Is Outlook.ContactItem) Then
                    Dim contactItem As Outlook.ContactItem = _
                       TryCast(selObject, Outlook.ContactItem)
                    itemMessage = "The item is a contact." & _
                        " The full name is " & _
                        contactItem.Subject & "."
                    contactItem.Display(False)
                ElseIf (TypeOf selObject Is Outlook. _
                    AppointmentItem) Then
                    Dim apptItem As Outlook.AppointmentItem = _
                       TryCast(selObject, Outlook.AppointmentItem)
                    itemMessage = "The item is an appointment." _
                        & apptItem.Subject & "."
                ElseIf (TypeOf selObject Is Outlook.TaskItem) Then
                    Dim taskItem As Outlook.TaskItem = _
                        TryCast(selObject, Outlook.TaskItem)
                    itemMessage = "The item is a task." & _
                        " The body is " & taskItem.Body & "."
                ElseIf (TypeOf selObject Is Outlook.MeetingItem) Then
                    Dim meetingItem As Outlook.MeetingItem = _
                        TryCast(selObject, Outlook.MeetingItem)
                    itemMessage = "The item is a meeting item. " & _
                        "The subject is " & meetingItem.Subject & "."
                End If
            End If
            expMessage = expMessage & itemMessage
        Catch ex As Exception
            expMessage = ex.Message
        End Try
        MessageBox.Show(expMessage)
    End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值