• RyanDev.com

  • Microsoft Outlook Daylight Savings Fix for Calendar

16th February 2008

Microsoft Outlook Daylight Savings Fix for Calendar

There is a setting on a Windows PC to “Automatically adjust clock for daylight saving changes.” If you change this setting your appointments and meetings in your Microsoft Outlook calendar may be moved. Outlook does this intentionally and is not a bug.

Adjust daylight savings automatically

Below is a code sample of how to fix your appointments. 

Attribute VB_Name = “DayLightSavingsFix”Public Sub DayLightSavingsFix()‘***************************************************************************‘This macro will go through all items in a Calendar and change the start time to one hour back.‘It will ignore anything that is not an Appointment or a Meeting‘It will also ignore any all day events.‘This macro will change only items that were created before 1/1/08‘***************************************************************************

Dim CurFolder, MyItems

Dim NumItems As Integer, i As Integer

Dim MyItem As Object

‘Use whichever folder is currently selected

‘This means that you should run this macro with your Calendar folder selected.

Set CurFolder = Application.ActiveExplorer.CurrentFolder

‘Make sure the current folder is a Calendar folder

If CurFolder.DefaultItemType = 1 Then

‘get a handle on the items in the Calendar folder

Set MyItems = CurFolder.Items

NumItems = MyItems.Count

‘loop through all of the Calendar items

For i = 1 To NumItems

On Error Resume Next ‘ignore any errors

Set MyItem = MyItems.Item(i)

If TypeName(MyItem) = “AppointmentItem” Then

‘check to see if item was created before Jan 01 and not an all day event

If DateDiff(”d”, MyItem.CreationTime, “1/1/08 2:00:00 AM”) >= 1 And MyItem.AllDayEvent = False Then

‘change the start time back one hour, end time is automatically adjusted

MyItem.Start = DateAdd(”h”, -1, MyItem.Start)

MyItem.Save

End If

ElseIf TypeName(MyItem) = “MeetingItem” Then

‘check to see if item was created before Jan 1 and not an all day event

If DateDiff(”d”, MyItem.CreationTime, “1/1/08 2:00:00 AM”) >= 1 And MyItem.GetAssociatedAppointment.AllDayEvent = False Then

‘change the start time back one hour, end time is automatically adjusted

MyItem.GetAssociatedAppointment.Start = DateAdd(”h”, -1, MyItem.GetAssociatedAppointment.Start)

MyItem.Save

End If

End If

Next i

MsgBox “Done”

Else

MsgBox “The current folder needs to be a Calendar folder before running this macro.”

End If

‘ Cleanup

Set MyItem = Nothing

Set MyItems = Nothing

Set CurFolder = Nothing

End Sub

To run this code, open Microsoft Outlook and click Tools, Marco, Visual Basic Editor.  Your screen may look something like the following.

Outlook VBA
 

Paste the code into the right side.  Adjust the date for your own needs. 

Note: This code has been tested and confirmed with Microsoft Outlook versions 2000, 2002 and 2003.   The complete code can also be downloaded here.

posted in Microsoft Office, Microsoft Outlook | 2 Comments

  • Links

  • Calendar

  • September 2010
    S M T W T F S
    « Jun    
     1234
    567891011
    12131415161718
    19202122232425
    2627282930