应用程序定义的问题Outlook导出到Excel

时间:2019-02-22 08:19:40

标签: excel vba outlook

我要在Outlook中检索邮件内容的部分出现Application defined or Object defined错误。这是我的代码

Sub Import_Outlook_to_Excel()
    Dim oitem As outlook.MailItem
    Dim i As Long
    Dim Body As String
    Dim olapp As outlook.Application
    Dim olappns As outlook.Namespace
    Dim oinbox As outlook.Folder
    Dim oFolder As outlook.MAPIFolder

    i = 2    outlook
    Set olapp = New outlook.Application
    Set olappns = olapp.GetNamespace("MAPI")
    Set oinbox = olappns.GetDefaultFolder(olFolderInbox).Folders("Winautomation")

    For Each oitem In oinbox.Items
        Sheets(1).Cells(i, 5).Value = oitem.Subject
        Sheets(1).Cells(i, 6).Value = oitem.Body
        i = i + 1
    Next
End Sub

0 个答案:

没有答案