Outlook字段和等效属性 [英] Outlook Fields and Equivalent Properties

查看:116
本文介绍了Outlook字段和等效属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宏可以让excel从共享邮箱中获取所有电子邮件 在我的共享收件箱中,我创建了2个新字段,我们在其中输入一些与收到的电子邮件相关的信息.我已经将它们命名为Client和Oper.

I have a macro to get in excel all the emails from a shared mailbox In my shared inbox I have created 2 new fields where we enter some information related to the emails received. I have named them Client and Oper.

您能帮我一个建议吗?如何在VBA中查看字段属性以获取它?

Can you help me please with a suggestion? How can I see the field property in order to get it in VBA?

宏看起来像这样:

Option Explicit
Sub getDataFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim objOwner As Outlook.Recipient
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set objOwner = OutlookNamespace.CreateRecipient("Sharedmailbox@companyname.com")
objOwner.Resolve
If objOwner.Resolved Then
Set Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox)
End If
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("email_receipt_date").Value Then
Range("email_sender").Offset(i, 0) = OutlookMail.SenderName
        Range("email_sender").Offset(i, 0).Columns.AutoFit
        Range("email_sender").Offset(i, 0).VerticalAlignment = xlTop
        Range("email_subject").Offset(i, 0) = OutlookMail.Subject
        Range("email_subject").Offset(i, 0).Columns.AutoFit
        Range("email_subject").Offset(i, 0).VerticalAlignment = xlTop
      'Range("email_client").Offset(i, 0) = OutlookMail.Client
      'Range("email_client").Offset(i, 0).Columns.AutoFit
        'Range("email_client").Offset(i, 0).VerticalAlignment = xlTop
        'Range("email_oper").Offset(i, 0) = OutlookMail.Oper
        'Range("email_oper").Offset(i, 0).Columns.AutoFit
        'Range("email_oper").Offset(i, 0).VerticalAlignment = xlTop
        Range("email_date").Offset(i, 0) = OutlookMail.ReceivedTime
        Range("email_date").Offset(i, 0).Columns.AutoFit
        Range("email_date").Offset(i, 0).VerticalAlignment = xlTop
        Range("email_categories").Offset(i, 0) = OutlookMail.Categories
        Range("email_categories").Offset(i, 0).Columns.AutoFit
        Range("email_categories").Offset(i, 0).VerticalAlignment = xlTop
        Range("email_flag_status").Offset(i, 0) = OutlookMail.FlagStatus
        Range("email_flag_status").Offset(i, 0).Columns.AutoFit
        Range("email_flag_status").Offset(i, 0).VerticalAlignment = xlTop
 i = i + 1
    End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub

推荐答案

您可以使用MailItem的UserProperties.

You can utilize the UserProperties of the MailItem.

例如OutlookMail.UserProperties("Oper").Value将返回您创建的属性字段的值.

For example OutlookMail.UserProperties("Oper").Value will return the value of that property field you created.

请注意,如果该字段未填充,将导致错误,因此建议您预先使用Find进行IF检查,以确保不会引发异常.

Note that it WILL cause an error it that field is not populated so it is suggested to use Find beforehand with an IF check to ensure you don't throw an exception.

If Not(OutlookMail.UserProperties.Find("Oper", True) Is Nothing) Then
    'Do stuff with OutlookMail.UserProperties("Oper").Value
End If

这篇关于Outlook字段和等效属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆