F
Fil
Hi,
I am trying to save the birthdays of some friends programmaticaly from an
Excel spreadsheet into Outlook as AppointmentItems (First column of excel
spreadsheet is the date and the second is the name). I want them to be
AllDayEvent=true and to start at midnight as per the Time Zone where my
friend lives (let say GMT+1 in the example). So I wrote the below code:
----------------------------------------------------------------------------------------
Public Sub test()
Dim otl As New Outlook.Application
Dim cal As Outlook.Folder
Dim newItem As Outlook.AppointmentItem
Dim rec As Outlook.RecurrencePattern
Dim tz_Paris As Outlook.TimeZone
Set tz_Paris = Outlook.TimeZones("Romance Standard Time")
Set cal = otl.GetNamespace("MAPI").Folders("Personal
Folders").Folders("Calendar")
While Not IsEmpty([a1].Offset(i, 0))
Set newItem = cal.Items.Add(olAppointmentItem)
newItem.Subject = "Birthday of " & [a1].Offset(i, 1).Value
Set rec = newItem.GetRecurrencePattern
rec.RecurrenceType = olRecursYearly
rec.DayOfMonth = CInt(Mid(Format([a1].Offset(i, 0).Value, "ddmmyy"), 1,
2))
rec.MonthOfYear = Mid(Format([a1].Offset(i, 0).Value, "ddmmyy"), 1 + 2, 2)
rec.NoEndDate = True
rec.StartTime = [a1].Offset(i, 0).Value
newItem.StartTimeZone = tz_Paris
newItem.EndTimeZone = newItem.StartTimeZone
newItem.StartInStartTimeZone = [a1].Offset(i, 0).Value
newItem.AllDayEvent = True 'Doesn't work
newItem.Duration = 24 * 60 'Doesn't work
newItem.Save
Set newItem = Nothing
Set rec = Nothing
i = i + 1
Wend
End Sub
----------------------------------------------------------------------------------------
When the AppointmentItems are saved in Outlook, they are 30 minutes long and
with start and end time specified as per GMT, even if I tried in 2 different
ways to tell outlook this is an AllDayEvent and to consider times in GMT+1.
My instructions work (I can see they work when I look at the objects in the
watch window) but when they are saved some properties are reset to default.
Do you know that problem? (I remember that in the past I had problems with
Categories, it might be the same issue)
I am trying to save the birthdays of some friends programmaticaly from an
Excel spreadsheet into Outlook as AppointmentItems (First column of excel
spreadsheet is the date and the second is the name). I want them to be
AllDayEvent=true and to start at midnight as per the Time Zone where my
friend lives (let say GMT+1 in the example). So I wrote the below code:
----------------------------------------------------------------------------------------
Public Sub test()
Dim otl As New Outlook.Application
Dim cal As Outlook.Folder
Dim newItem As Outlook.AppointmentItem
Dim rec As Outlook.RecurrencePattern
Dim tz_Paris As Outlook.TimeZone
Set tz_Paris = Outlook.TimeZones("Romance Standard Time")
Set cal = otl.GetNamespace("MAPI").Folders("Personal
Folders").Folders("Calendar")
While Not IsEmpty([a1].Offset(i, 0))
Set newItem = cal.Items.Add(olAppointmentItem)
newItem.Subject = "Birthday of " & [a1].Offset(i, 1).Value
Set rec = newItem.GetRecurrencePattern
rec.RecurrenceType = olRecursYearly
rec.DayOfMonth = CInt(Mid(Format([a1].Offset(i, 0).Value, "ddmmyy"), 1,
2))
rec.MonthOfYear = Mid(Format([a1].Offset(i, 0).Value, "ddmmyy"), 1 + 2, 2)
rec.NoEndDate = True
rec.StartTime = [a1].Offset(i, 0).Value
newItem.StartTimeZone = tz_Paris
newItem.EndTimeZone = newItem.StartTimeZone
newItem.StartInStartTimeZone = [a1].Offset(i, 0).Value
newItem.AllDayEvent = True 'Doesn't work
newItem.Duration = 24 * 60 'Doesn't work
newItem.Save
Set newItem = Nothing
Set rec = Nothing
i = i + 1
Wend
End Sub
----------------------------------------------------------------------------------------
When the AppointmentItems are saved in Outlook, they are 30 minutes long and
with start and end time specified as per GMT, even if I tried in 2 different
ways to tell outlook this is an AllDayEvent and to consider times in GMT+1.
My instructions work (I can see they work when I look at the objects in the
watch window) but when they are saved some properties are reset to default.
Do you know that problem? (I remember that in the past I had problems with
Categories, it might be the same issue)