-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
什麼是你的代碼的相關代碼段?哪一行引發異常?什麼是**精確**異常? –
@DmitryStreblechenko它的標籤是VBA,所以不會有* exception *(這將是一個.net事物),而是一個「運行時錯誤」。但是,是的,絕對同意 - 沒有任何代碼和附加信息,這個問題沒有什麼可做的。 –
這些異常將是標準的COM異常 - OOM不知道或關心它是否正在使用VBA。 Net,Delphi或C++。例外情況絕對不是.Net特定的。 VBA(這是基於COM)只是有一個有趣的方式來處理他們使用「錯誤...」等 –