Option
Explicit
Public
Sub
ReadMailItems()
Dim
olapp
As
Object
Dim
olName
As
Object
Dim
olHFolder
As
Object
Dim
olUFolder
As
Object
Dim
olUFolder2
As
Object
Dim
strAttCount
As
String
Dim
olItemsCount
As
Long
Dim
olItemsCount2
As
Long
Dim
lngAttCount
As
Long
Dim
Zeile
As
Long
Dim
VonDatum
As
Date
, BisDatum
As
Date
Set
olapp = CreateObject(
"Outlook.Application"
)
Set
olName = olapp.GetNamespace(
"MAPI"
)
Set
olHFolder = olName.Session.Folders(
"Funktionspostfach"
)
Set
olUFolder = olHFolder.Folders(
"Posteingang"
)
Set
olUFolder2 = olHFolder.Folders(
"1.01 in Bearbeitung"
)
[A1].Value =
"E-Mail-Ordner"
[B1].Value =
"MailFrom"
[C1].Value =
"Exchange ID"
[D1].Value =
"Datum//Uhrzeit"
[E1].Value =
"Betreff"
[F1].Value =
"Text"
[G1].Value =
"Anzahl Datei-Anhang"
[H1].Value =
"Datei-Anhang"
[I1].Value =
"Datei-Größe"
[J1].Value =
"CC"
[K1].Value =
"Empfänger"
Rows(1).Font.Bold =
True
VonDatum =
CDate
(InputBox(
"Bitte Datum des ersten zu betrachtenden Tages eingeben:"
,
"Datumseingabe"
, Format(Now - 1,
"DD.MM.YYYY"
)))
BisDatum =
CDate
(InputBox(
"Bitte Datum des letzten zu betrachtenden Tages eingeben:"
,
"Datumseingabe"
, Format(Now,
"DD.MM.YYYY"
)))
VonDatum = DateSerial(Year(VonDatum), Month(VonDatum), Day(VonDatum))
BisDatum = DateSerial(Year(BisDatum), Month(BisDatum), Day(BisDatum) + 1)
Zeile = Sheets(
"Master"
).Range(
"A"
& Rows.Count).
End
(xlUp).Row
For
olItemsCount = 1
To
olUFolder.Items.Count
With
olUFolder.Items.Item(olItemsCount)
If
VonDatum <= .ReceivedTime
And
.ReceivedTime < BisDatum
Then
Zeile = Zeile + 1
For
lngAttCount = 1
To
.Attachments.Count
If
strAttCount =
""
Then
strAttCount = .Attachments.Item(lngAttCount).Filename
Else
strAttCount = strAttCount & vbCrLf & .Attachments.Item(lngAttCount).Filename
End
If
Next
lngAttCount
Sheets(
"Master"
).Range(
"A"
& Zeile).Value = olHFolder.Name &
"->"
& olUFolder.Name
Sheets(
"Master"
).Range(
"B"
& Zeile).Value = .Sender
Sheets(
"Master"
).Range(
"C"
& Zeile).Value = .SenderEmailAddress
Sheets(
"Master"
).Range(
"D"
& Zeile).Value = .ReceivedTime
Sheets(
"Master"
).Range(
"E"
& Zeile).Value = .Subject
Sheets(
"Master"
).Range(
"F"
& Zeile).Value = .body
Sheets(
"Master"
).Range(
"G"
& Zeile).Value = .Attachments.Count
Sheets(
"Master"
).Range(
"H"
& Zeile).Value = strAttCount
Sheets(
"Master"
).Range(
"I"
& Zeile).Value = .Size
Sheets(
"Master"
).Range(
"J"
& Zeile).Value = .cc
Sheets(
"Master"
).Range(
"K"
& Zeile).Value = .
To
strAttCount =
""
end if
end with
next
For
olItemsCount2 = 1
To
olUFolder2.Items.Count
With
olUFolder2.Items.Item(olItemsCount2)
If
VonDatum <= .ReceivedTime
And
.ReceivedTime < BisDatum
Then
Zeile = Zeile + 1
For
lngAttCount = 1
To
.Attachments.Count
If
strAttCount =
""
Then
strAttCount = .Attachments.Item(lngAttCount).Filename
Else
strAttCount = strAttCount & vbCrLf & .Attachments.Item(lngAttCount).Filename
End
If
Next
lngAttCount
Sheets(
"Master"
).Range(
"A"
& Zeile).Value = olHFolder.Name &
"->"
& olUFolder2.Name
Sheets(
"Master"
).Range(
"B"
& Zeile).Value = .Sender
Sheets(
"Master"
).Range(
"C"
& Zeile).Value = .SenderEmailAddress
Sheets(
"Master"
).Range(
"D"
& Zeile).Value = .ReceivedTime
Sheets(
"Master"
).Range(
"E"
& Zeile).Value = .Subject
Sheets(
"Master"
).Range(
"F"
& Zeile).Value = .body
Sheets(
"Master"
).Range(
"G"
& Zeile).Value = .Attachments.Count
Sheets(
"Master"
).Range(
"H"
& Zeile).Value = strAttCount
Sheets(
"Master"
).Range(
"I"
& Zeile).Value = .Size
Sheets(
"Master"
).Range(
"J"
& Zeile).Value = .cc
Sheets(
"Master"
).Range(
"K"
& Zeile).Value = .
To
strAttCount =
""
end if
End
With
Next
End
Sub