通过Excel VBA获取共享邮箱的Outlook类别标签

时间:2018-11-13 14:32:54

标签: excel vba outlook categories

我有工作代码,可以从Outlook中的共享邮箱中提取电子邮件。我还尝试提取此电子邮件已分配的“类别”。

例如:电子邮件到达并分配给可能被标记为“已完成”的红色类别,被标记为“需要注意”的蓝色类别,等等。

我想要创建类别标签名称,但不断收到错误提示:

  

运行时错误'1004'应用程序定义的错误或对象定义的错误。

Sub GetfromOutlook2() 

Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Outlook.Namespace
Dim targetFolder As Outlook.MAPIFolder
Dim firstFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem

Dim objCategory As Category

Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set firstFolder = OutlookNamespace.Folders("Mailbox Name")
Set targetFolder = firstFolder.Folders("Inbox")
Set HiperosFolder = targetFolder.Folders("00 - Production")

i = 1

For Each OutlookMail In HiperosFolder.Items

    If OutlookMail.ReceivedTime >= Range("From_date").Value Then
        Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
        Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
        Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
        Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body

        'Range("eMail_category").Offset(i, 0).Value = Outlook.Category 'failed

        ' The line with the error: Application-define or object-defined error
        Range("eMail_category").Offset(i, 0).Value = objCategory 'another attempt 

        i = i + 1
    End If
Next OutlookMail

Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub

0 个答案:

没有答案