2017-01-24 10 views
-2

Importieren von E-Mails von Outlook 2013 zu Excel 2013 funktioniert mit Home Desktop. Outlook 2013 ist mit dem SMTP/POP-Server verbunden.Importieren von E-Mails von Outlook 2013 mit Exchange-Server mit Excel VBA

Derselbe Code funktioniert nicht in meinem Büro. Outlook 2013 ist mit dem Exchange-Server verbunden.

Fehler bei .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

Und was ist mit Ihrem Code ist der entsprechende Code-Schnipsel? Welche Zeile löst die Ausnahme aus? Was ist die ** genaue ** Ausnahme? –

+1

@DmitryStreblechenko es ist mit VBA getaggt, so würde es nicht eine * Ausnahme * (das wäre eine. Net-Sache), aber ein "Laufzeitfehler" sein. Aber ja, ich stimme Ihnen definitiv zu - mit dieser Frage ist nichts ohne Code und zusätzliche Informationen zu machen. –

+1

Die Ausnahmen wären Standard-COM-Ausnahmen - OOM weiß nicht, ob es von VBA verwendet wird. Net, Delphi oder C++. Ausnahmen sind definitiv nicht .Net-spezifisch. VBA (die auf COM basiert) hat nur eine lustige Art der Handhabung von ihnen mit "auf Fehler ..." usw. –

Antwort

1

Kreuz Posting ist gut, aber erwähnen immer die Links in beiden Threads.

Importing outlook emails to excel in 2013 version.

einfach mit Excel/Outlook2013 auf Exchange Server verbunden getestet & nicht das Problem repliziert hat.

Erhalten Sie Fehler bei der ersten E-Mail oder in einer bestimmten E-Mail?

Überprüfen Sie jedoch mit den folgenden Änderungen.

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 
Verwandte Themen