使用VBA /宏在Excel中导入Outlook用户定义的字段

问题描述 投票:1回答:1

很抱歉打扰您,但我的其中一个宏遇到一些困难。

在Excel上,我想从Outlook导入邮件数据。我可以导入经典字段,例如:发件人,主题...等。但是我找不到如何导入“用户定义的字段”的问题。

我尝试导入的用户定义字段被命名为“ DemandQTY”,并且仅包含数字。

我从中获取数据的邮箱是共享邮箱。

Sub GetFromOutlook()

Dim OutApp As Outlook.Application
Dim OutNS As Namespace
Dim Folder As MAPIFolder
Dim OutMail As Variant
Dim i As Integer
Dim objOwner As Outlook.Recipient
Dim FileName As String
Dim MI As Outlook.MailItem
Dim Item As Object
Dim Atmt As Attachment

Set OutNS = GetNamespace("MAPI")
Set OutApp = New Outlook.Application
Set objOwner = OutNS.CreateRecipient("emailadress")
objOwner.Resolve

If objOwner.Resolved Then
Set Folder = OutNS.GetSharedDefaultFolder(objOwner, olFolderInbox)

i=2
For Each OutMail In Folder.Items

        Sheets(2).Cells(i, 1) = OutMail.EntryID
       (etc....)
        Sheets(2).Cells(i, 32) = OutMail.ReminderTime    
        i = i + 1
Next OutMail
MsgBox "Importation Terminée"
Sheets(2).Select
Sheets(2).Cells(1, 1).Select
Set OutApp = Nothing
Set OutNS = Nothing
Set Folder = Nothing
End If
End Sub

老实说,我没有在Outlook中大量使用VBA。我尝试了很多在Internet上找到的不同方法,但是没有任何效果。

我希望有人会有一个主意:)

谢谢,

excel vba import outlook-vba
1个回答
0
投票
For Each OutMail In Folder.Items Sheets(2).Cells(i, 1) = OutMail.EntryID (etc....) Sheets(2).Cells(i, 32) = OutMail.ReminderTime If Not(OutMail.UserProperties.Find("DemandQTY", True) Is Nothing) Then Sheets(2).Cells(i, 33) = OutMail.UserProperties("DemandQTY").Value End If i = i + 1 Next OutMail
© www.soinside.com 2019 - 2024. All rights reserved.