将表格数据从电子邮件导出到Excel列

时间:2019-12-19 20:55:37

标签: excel vba parsing email-parsing

我正在尝试从电子邮件中提取像表格一样设置的数据。有谁知道我如何遍历电子邮件内容以检查表,以及是否可以将数据导出到Excel中的列?现在,我刚刚返回的代码将返回主题,发送者和发送时间。

Sub GetMCInboxLeads()

    Dim ol As Outlook.Application
    Dim ns As Outlook.Namespace
    Dim fol As Outlook.Folder
    Dim i As Object
    Dim mi As Outlook.MailItem         
    Dim n As Long 
    Dim rh As Double
    Dim objOwner As Outlook.Recipient

    Set ol = New Outlook.Application
    Set ns = ol.GetNamespace("MAPI")
    Set fol = ns.GetDefaultFolder(olFolderInbox)
    Set objOwner = ns.CreateRecipient("xx@xxx.com")
    objOwner.Resolve

    If objOwner.Resolved Then
        Set fol = ns.GetSharedDefaultFolder(objOwner, olFolderInbox)
    End If

    Worksheets.Add
    rh = Range("A1").RowHeight
    'i = 1

    For Each i In fol.Items

        If i.Class = olMail Then

            n = n + 1 

            Set mi = i
            'Debug.Print mi.Subject, mi.SenderName, mi.ReceivedTime

            Cells(n, 1).Value = mi.SenderName
            Cells(n, 2).Value = mi.Subject
            Cells(n, 3).Value = mi.ReceivedTime
            Cells(n, 4).Value = mi.Body
        End If

    Next i


    Range("A1").CurrentRegion.EntireColumn.AutoFit
    Range("A1").CurrentRegion.EntireRow.RowHeight = rh

0 个答案:

没有答案