簡體   English   中英

使用 VBA 將 Outlook 用戶定義字段導入 Excel

[英]Import Outlook User-Defined Field to Excel with VBA

我想從 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

我嘗試了在互聯網上找到的不同方法,但沒有任何效果。

我們可以通過首先測試屬性是否存在來做到這一點。 如果沒有,並且您嘗試使用它,它將引發錯誤。 之后,如果找到該屬性,我們就可以訪問該值。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM