使用exchange server和Excel VBA从Outlook 2013导入电子邮件

使用exchange server和Excel VBA从Outlook 2013导入电子邮件,excel,vba,outlook,Excel,Vba,Outlook,将电子邮件从Outlook 2013导入Excel 2013适用于home desktop。Outlook 2013已连接到SMTP/POP服务器 同样的代码在我的办公室里不起作用。Outlook 2013已连接到exchange server 在.Senderemailaddress处出错 Option Explicit Dim n As Long Sub Get_data() Dim olApp As Outlook.Application Dim olNS As Outlook.Name

将电子邮件从Outlook 2013导入Excel 2013适用于home desktop。Outlook 2013已连接到SMTP/POP服务器

同样的代码在我的办公室里不起作用。Outlook 2013已连接到exchange server

在.Senderemailaddress处出错

Option Explicit
Dim n As Long
Sub Get_data()

Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim Date1, Date2
Date1 = "01/26/2017"

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
n = 2
Call Get_Emails(olFolder, Date1)

Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub

Sub Get_Emails(olfdStart As Outlook.MAPIFolder, Date1)
Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olMail As Outlook.MailItem
Dim Recivedt As Date

For Each olObject In olfdStart.Items
    If TypeName(olObject) = "MailItem" Then

        If olObject.ReceivedTime <= Date1 Then
            n = n + 1
            Set olMail = olObject
             'Sno
            Cells(n, 1) = n
             'Universal id
            Cells(n, 2) = olMail.ConversationID
             'Email id

            'Getting debug error here as not supported.
            Cells(n, 3) = olMail.SenderEmailAddress '**

             'Date and time workings
            Cells(n, 4) = olMail.ReceivedTime
             'Size
            Cells(n, 6) = olMail.Size

             'Subject
            Cells(n, 7) = olMail.Subject

        End If
    End If
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub
选项显式
长
子获取_数据()
Dim olApp作为Outlook.Application
将OLN设置为Outlook.Namespace
将文件夹设置为Outlook.MAPIFolder
日期1,日期2
日期1=“2017年1月26日”
设置olApp=Outlook.Application
Set olNS=olApp.GetNamespace(“MAPI”)
设置olFolder=olNS.PickFolder
n=2
呼叫获取电子邮件(文件夹,日期1)
设置olNS=Nothing
设置olFolder=Nothing
设置olApp=Nothing
设置olNS=Nothing
端接头
子获取电子邮件(olfdStart作为Outlook.MAPI文件夹,日期1)
将文件夹设置为Outlook.MAPIFolder
作为对象的Dim对象
以Outlook.MailItem的形式发送邮件
Dim接收日期
对于olfdStart.Items中的每个olObject
如果TypeName(olObject)=“MailItem”,则

如果olObject.ReceivedTime交叉发布是好的,但始终在两个线程中提及链接

刚刚使用连接到Exchange Server的Excel/Outlook2013进行了测试,但没有复制此问题

你是在第一封邮件中还是在一封特定的邮件中出错

但是,请检查以下更改

Function Get_Sender_Address(oMsg As Outlook.MailItem) As String
Dim oExUser As Outlook.ExchangeUser, oAddType As Outlook.AddressEntry

Set oAddType = oMsg.Sender

If oAddType.AddressEntryUserType = olExchangeUserAddressEntry Then
    Set oExUser = oAddType.GetExchangeUser
        Get_Sender_Address = oExUser.PrimarySmtpAddress
Else
    Get_Sender_Address = oMsg.SenderEmailAddress
End If

Set oAddType = Nothing:    Set oExUser = Nothing

End Function
&


您的代码的相关片段是什么?哪一行引发异常?确切的异常是什么?@DmitryStreblechenko它用VBA标记,因此不会有异常(这将是一个.net的东西),而是一个“运行时错误”。但是,是的,绝对同意-如果没有任何代码和附加信息,这个问题将无法解决。例外情况将是标准的COM例外情况-OOM不知道或不关心是否从VBA使用它。NET、Delphi或C++。例外情况绝对不是特定于.Net的。VBA(基于COM)只是有一种有趣的方式来处理它们,使用“出错…”等。各位专家好…问题基本上是在Excel VBA上,它在家里工作正常,但在我的办公室里工作不正常。发布我的问题这可能是outlook 2013连接到exchange server。。。没有选项附加显示代码的文件…请帮助========================================================
Cells(n, 3) = Get_Sender_Address(olMail) 'olMail.SenderEmailAddress