AW: XL2Outlook: keine doppelten Kalendereinträge
Ramses
Hallo
bei VBA Gut kannst du den Code sicher anpassen.
Mit dem Code kannst du Termindaten abfragen.
Mit einer IF-Abfrage kannst du ".Start" des Items mit deinem TErmin vergleichen, und somit entscheiden, ob du eintragen willst oder nicht.
Sub Read_Control_Termin_to_Excel()
'by Ramses
'Datumsabfage über Inputbox
'Verweis auf Outlook 11 Library im VB-Editor muss gesetzt sein
Dim myR As Integer, i As Integer
Dim startDate As Date, endDate As Date, recDate As Date, extDate As Date
Dim myOlApp As Object, myOlSpace As Object, myOlFolder As Object
Dim myOlDateRange As Object, sAppoint As Object
Dim extRecurr As Object
Dim strRecurr As String
'Datum vorschlagen
Select Case Weekday(Now + 1, vbMonday)
Case Is > 5
recDate = Now + 3
Case Else
recDate = Now + 1
End Select
'Datum abfragen
startDate = Format(DateValue(InputBox("Welches Datum soll abgefragt werden ?" & Chr$(13) & _
"Datum muss im Format ""01.01.2004"" eingeben werden", "Terminsuche", Format(recDate, "dd.mm.yyyy"))))
endDate = startDate
'Deklaration
Set myOlApp = CreateObject("Outlook.Application")
Set myOlSpace = myOlApp.GetNamespace("MAPI")
Set myOlFolder = myOlSpace.GetDefaultFolder(olFolderCalendar)
'Einträge ab Zeile 2
myR = 2
'Löscht alle zellen in der aktiven Tabelle
Cells.ClearContents
Cells.Interior.ColorIndex = xlNone
Cells(1, 1) = "Termin"
Cells(1, 2) = "Dauer"
Cells(1, 3) = "Ende"
Cells(1, 4) = "Ort"
Cells(1, 5) = "Betreff"
Cells(1, 6) = "Textinfo"
Set myOlDateRange = myOlFolder.Items.Restrict("[Start] >= '" & startDate & "' And [End] < & '" & endDate + 1 & "'")
For Each sAppoint In myOlDateRange
With sAppoint
'Termindaten eintragen
Cells(myR, 1) = Format(.start, "dd.mm.yyyy hh:mm")
Cells(myR, 2) = Format((((1 / 24) / 60) * .Duration), "hh:mm")
Set extRecurr = .GetRecurrencePattern
'OlRecurrenceType sein:
'olRecursDaily = 1
'olRecursMonthly = 2
'olRecursMonthNth = 3
'olRecursWeekly = 4
'olRecursYearly = 5
'olRecursYearNth = 6
Select Case extRecurr.RecurrenceType
Case 1
strRecurr = "Täglich für "
Case 2
strRecurr = "Monatlich für "
Case 3
strRecurr = "Monatlich jeden "
Case 4
strRecurr = "Wöchentlich für "
Case 5
strRecurr = "Jährlich für "
Case 6
strRecurr = "Jährlich jeden "
End Select
If Format(extRecurr.PatternEndDate, "dd.mm.yyyy") <> Format(DateValue("31.12.4500"), "dd.mm.yyyy") Then
Cells(myR, 3) = Format(DateValue(extRecurr.PatternEndDate), "dd.mm.yyyy")
Cells(myR, 3).Interior.ColorIndex = 3
Cells(myR, 7) = strRecurr & DateValue(Format(extRecurr.PatternEndDate, "dd.mm.yyyy")) - startDate + 1 & " Tage"
Else
Cells(myR, 3) = Format(.start + (((1 / 24) / 60) * .Duration), "hh:mm")
End If
Cells(myR, 4) = .Location
Cells(myR, 5) = .Subject
Cells(myR, 6) = .Body
myR = myR + 1
End With
Next
'Variablen leeren
Set myOlApp = Nothing
Set myOlSpace = Nothing
Set myOlFolder = Nothing
MsgBox "Alle Termine für den " & startDate & " eingelesen!"
End Sub
Gruss Rainer