Excel VBA - Emailbody aus Outlook auslesen

Ok. Ich habe das mit Split gelöst.

Aber jetzt sagt er, dass ich ein Objekt brauche und ich verstehe nicht warum.

Und zwar bei
Code:
ioWsZiel.Range("A" & nextRowNr).Text = Datum


Visual Basic:
Public Sub mailTest2()
 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
        .Cursor = xlWait
    End With
     
    Const C_MAPI = "jerry5428@hotmail.com"
    Const C_FOLDER = "Test"

    Dim otl         As Outlook.Application
    Dim ns          As Outlook.Namespace
    Dim fld         As Outlook.MAPIFolder
    Dim mail        As Outlook.MailItem
    Dim lArrayIndex As Variant
    Dim i           As Long
    Dim WrdArray()  As String
    Dim text_string As String
    Dim nextRowNr   As Long
    Dim ioWsZiel    As Worksheet
    Dim iMail       As Object
    Dim Datum       As Date

    Set otl = New Outlook.Application
    Set ns = otl.GetNamespace("MAPI")
    Set fld = ns.Folders(C_MAPI).Folders(C_FOLDER)
    Set ioWsZiel = ThisWorkbook.Worksheets("Gesamt Eingang")

    nextRowNr = ioWsZiel.UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1

    For Each mail In fld.Items
 
        Datum = mail.ReceivedTime - 1
        text_string = mail.Body
        WrdArray() = Split(text_string)
     

        If mail.Subject Like "*jerry5428@hotmail.com*" Then
         
            ioWsZiel.Range("A" & nextRowNr).Text = Datum
            ioWsZiel.Range("B" & nextRowNr).Value = "jerry5428@hotmail.com"
            ioWsZiel.Range("C" & nextRowNr).Value = WrdArray(1)
            ioWsZiel.Range("D" & nextRowNr).Value = WrdArray(2)
     
        End If
     
        nextRowNr = nextRowNr + 1
    Next
 
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
        .Cursor = xlDefault
    End With
 
End Sub
 
Zuletzt bearbeitet:
Hab es selber gelöst :D

ioWsZiel.Range("A" & nextRowNr).Text = Datum

in

ioWsZiel.Range("A" & nextRowNr).Value = Datum

geändert :cool:
 
Ich habe doch ein Problem:

Ich habe jetzt mir dem Split den Text getrennt und nutze dann das Array für das Einsetzen der Werte.

Visual Basic:
        If mail.Subject Like "*jerry5428@hotmail.com*" Then

            ioWsZiel.Range("A" & nextRowNr).Value = Datum
            ioWsZiel.Range("B" & nextRowNr).Value = "jerry5428@hotmail.com"
            ioWsZiel.Range("C" & nextRowNr).Value = WrdArray(10)
            ioWsZiel.Range("C" & nextRowNr).Value = Replace(Range("C" & nextRowNr).Value, Chr(10), "")
            ioWsZiel.Range("C" & nextRowNr).Value = Trim(Range("C" & nextRowNr).Value)
            ioWsZiel.Range("C" & nextRowNr).Value = Replace(Range("C" & nextRowNr).Value, "Total", "")
            ioWsZiel.Range("C" & nextRowNr).NumberFormat = "0.00"
            ioWsZiel.Range("D" & nextRowNr).Value = WrdArray(13)
            ioWsZiel.Range("D" & nextRowNr).Value = Replace(Range("D" & nextRowNr).Value, Chr(10), "")
            ioWsZiel.Range("D" & nextRowNr).Value = Trim(Range("D" & nextRowNr).Value)
            ioWsZiel.Range("D" & nextRowNr).Value = Replace(Range("D" & nextRowNr).Value, "Total", "")
            ioWsZiel.Range("D" & nextRowNr).NumberFormat = "0.00"

Das Problem dabei ist, dass er auch die richtigen Daten einträgt ich diese aber nicht nutzen kann um diese dann in meiner Auswertung zu verwerten. Er erkennt die Werte nicht an.

Wenn ich eine Formel nutze wie z. B. Summenwenns dann erkennt er nicht, dass z. B. an einem bestimmten Datum Werte eingetragen wurden.
 
Zuletzt bearbeitet:
Ist nextRowNr abgefüllt oder Null?
Ist die Zelle gefüllt?
Ist klar, aif welcher Tabelle der Range-Befehl ausgeführt wird?
 
Wenn ich auf Debug klicke und die Zeile mir angucken dann ist nextRowNr mit "16" gefüllt.
Wenn ich mit der Maus über das Replace gehe steht da "Fehler 2042"
 

Neue Beiträge

Zurück