Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1860to1864
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Outlook Kalender Makro

Outlook Kalender Makro
04.01.2022 14:37:35
Bilbo
Hallo liebes Forum,
habe folgendes Makro zum Auslesen von Terminen aus Outlook Kalender in ein Excel-Blatt:

Sub ReadCalendarItems(Betreff As String)
Dim objApp As Outlook.Application
Dim objNS As Namespace
Dim objCalendar As MAPIFolder
Dim objItem As AppointmentItem
Dim strSubject As String
Dim ObjRecipient As Recipient
Dim i As Long
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)
i = 1
'Leere Blatt
Application.EnableEvents = False
Range("A4:Z4,A6:Z6,A8:Z8,A10:Z10").ClearContents
Application.EnableEvents = True
For Each objItem In objCalendar.Items
With objItem
If InStr(1, LCase(.Subject), LCase(Betreff))  0 Then
Application.EnableEvents = False
If InStr(1, .Start, " ")  0 Then
If Left(.Start, InStr(1, .Start, " ") - 1) = Left(.End, InStr(1, .Start, " ") - 1) Then
'Resultat in Zellen schreiben
Cells(4, i).Value = Left(.Start, InStr(1, .Start, " ") - 1)
Else
Cells(4, i).Value = Left(.Start, InStr(1, .Start, " ") - 1) & " - " & Left(.End, InStr(1, .Start, " ") - 1)
End If
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1) & " - " & Mid(.End, InStr(1, .Start, " ") + 1)
Else
Cells(4, i).Value = .Start
End If
Cells(8, i).Value = .Subject
'Spalte formatieren
With Columns(i)
.ColumnWidth = 40
.Cells.Rows.AutoFit
.Cells.HorizontalAlignment = xlCenter
.Cells.VerticalAlignment = xlTop
End With
i = i + 1
Application.EnableEvents = True
End If
'   If .Recipients.Count > 0 Then
'     For Each ObjRecipient In .Recipients
'       Debug.Print ObjRecipient.Name & " / "  ' & ObjRecipient.Address
'     Next
'   End If
'End If
End With
Next
If i = 1 Then
MsgBox "Keine Eintraege gefunden", 16
Else
MsgBox "Kalender durchsucht.", 64
End If
End Sub
Bei der Ausgabe erscheint das Datum im Format "17:30 - 17:30", was ja auch sinnvoll sein kann, wenn ein Termin für einen Zeitraum geplant ist.
Nun möchte ich aber gerne, dass es im Format "17:30" angezeigt wird, wenn ich es nur für die Uhrzeit "17:30" plane.
Kann mir da jemand weiterhelfen?
Was muss ich am Makro verändern?
Vielen Dank.
Liebe Grüße

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Outlook Kalender Makro
04.01.2022 17:02:20
ChrisL
Hi
Folgende Zeile ändern:

Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1) & " - " & Mid(.End, InStr(1, .Start, " ") + 1)
neu:

If .Start = .End Then
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1)
Else
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1) & " - " & Mid(.End, InStr(1, .Start, " ") + 1)
End If
cu
Chris
AW: Outlook Kalender Makro
05.01.2022 04:19:52
Bilbo
Hallo Chris,
vielen Dank für die Nachricht. Ich habe die entsprechende Zeile durch Deinen Vorschlag ersetzt (s.u.), aber irgendwie hat es nicht funktioniert.
Was habe ich wohl falsch gemacht?
LG

Sub ReadCalendarItems(Betreff As String)
Dim objApp As Outlook.Application
Dim objNS As Namespace
Dim objCalendar As MAPIFolder
Dim objItem As AppointmentItem
Dim strSubject As String
Dim ObjRecipient As Recipient
Dim i As Long
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)
i = 1
'Leere Blatt
Application.EnableEvents = False
Range("A4:Z4,A6:Z6,A8:Z8,A10:Z10").ClearContents
Application.EnableEvents = True
For Each objItem In objCalendar.Items
With objItem
If InStr(1, LCase(.Subject), LCase(Betreff))  0 Then
Application.EnableEvents = False
If InStr(1, .Start, " ")  0 Then
If Left(.Start, InStr(1, .Start, " ") - 1) = Left(.End, InStr(1, .Start, " ") - 1) Then
'Resultat in Zellen schreiben
Cells(4, i).Value = Left(.Start, InStr(1, .Start, " ") - 1)
Else
Cells(4, i).Value = Left(.Start, InStr(1, .Start, " ") - 1) & " - " & Left(.End, InStr(1, .Start, " ") - 1)
End If
If .Start = .End Then
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1)
Else
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1) & " - " & Mid(.End, InStr(1, .Start, " ") + 1)
End If
Else
Cells(4, i).Value = .Start
End If
Cells(8, i).Value = .Subject
'Spalte formatieren
With Columns(i)
.ColumnWidth = 40
.Cells.Rows.AutoFit
.Cells.HorizontalAlignment = xlCenter
.Cells.VerticalAlignment = xlTop
End With
i = i + 1
Application.EnableEvents = True
End If
'   If .Recipients.Count > 0 Then
'     For Each ObjRecipient In .Recipients
'       Debug.Print ObjRecipient.Name & " / "  ' & ObjRecipient.Address
'     Next
'   End If
'End If
End With
Next
If i = 1 Then
MsgBox "Keine Eintraege gefunden", 16
Else
MsgBox "Kalender durchsucht.", 64
End If
End Sub

Anzeige
AW: Outlook Kalender Makro
05.01.2022 08:14:27
ChrisL
Hi
Dann versuch mal so...

If Mid(.Start, InStr(1, .Start, " ") + 1) = Mid(.End, InStr(1, .Start, " ") + 1) Then
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1)
Else
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1) & " - " & Mid(.End, InStr(1, .Start, " ") + 1)
End If
cu
Chris
AW: Outlook Kalender Makro
05.01.2022 12:15:28
Bilbo
Super, das hat geklappt.
Vielen Dank:)
LG
AW: Outlook Kalender Makro
09.01.2022 16:39:34
Bilbo
Hallo,
jetzt ist mir aufgefallen, dass die Uhrzeit im Format: "00:00:00" ausgegeben wird, also z.B. 15:30:00.
Was müsste ich noch ändern, damit es im Format "00:00:00" angezeigt wird?
Vielen Dank.
LG
Anzeige
AW: Outlook Kalender Makro
10.01.2022 13:06:55
ChrisL
Hi

If Mid(.Start, InStr(1, .Start, " ") + 1) = Mid(.End, InStr(1, .Start, " ") + 1) Then
Cells(6, i).Value = Mid(.Start, InStr(1, .Start, " ") + 1)
Cells(6, i).NumberFormat = "hh:mm"
Else
Cells(6, i).Value = Format(Mid(.Start, InStr(1, .Start, " ") + 1), "hh:mm") & " - " & Format(Mid(.End, InStr(1, .Start, " ") + 1), "hh:mm")
End If
cu
Chris

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige