2017-01-24 93 views
-2

將電子郵件從Outlook 2013導入Excel 2013可與家用桌面一起使用。 Outlook 2013連接到SMTP/POP服務器。從Outlook 2013導入帶有Excel VBA交換服務器的電子郵件

相同的代碼在我的辦公室不起作用。 Outlook 2013連接到交換服務器。

錯誤在.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 
+1

什麼是你的代碼的相關代碼段?哪一行引發異常?什麼是**精確**異常? –

+1

@DmitryStreblechenko它的標籤是VBA,所以不會有* exception *(這將是一個.net事物),而是一個「運行時錯誤」。但是,是的,絕對同意 - 沒有任何代碼和附加信息,這個問題沒有什麼可做的。 –

+1

這些異常將是標準的COM異常 - OOM不知道或關心它是否正在使用VBA。 Net,Delphi或C++。例外情況絕對不是.Net特定的。 VBA(這是基於COM)只是有一個有趣的方式來處理他們使用「錯誤...」等 –

回答

1

交叉張貼是好的,但總是提兩個線程的鏈接。

Importing outlook emails to excel in 2013 version.

與連接到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 

&

Cells(n, 3) = Get_Sender_Address(olMail) 'olMail.SenderEmailAddress 
相關問題