Copy calendar entries from PST to server in Outlook
It’s been a while since my last posting, and I according to my site stats, my 4 readers must be getting impatient for new material. Recently I got an HTC 8525 PocketPC. Now, I use personal folders in Outlook, so all of my calendar appointments are in there and not on the Exchange server. Being that ActiveSync is created by MicroSloth, we’re at version 4 and still do not have the ability to specify where we are synching to, for users with multiple data files. After quite a lot of searching, I found a number of applications to synch my local calendar with the server, but all were shareware or quite flaky actually. So, when in need, roll your own!
The VBA should be pretty straight forward.. I am in a rush currently, so I am posting only the source right now. I will put more of a write-up and explain it a bit more as soon as I am able to.
Dim objOutlookDim objNameSpaceDim objCalendarFolderSrcDim objCalendarFolderDestDim objItemsSrcDim objItemsDestDim ObjApptsSrcDim intModeConst olFolderCalendar = 9 Const olAppointmentItem = 1Sub CopyAppointments()Set objOutlook = CreateObject("Outlook.application") Set objNameSpace = objOutlook.GetNamespace("MAPI")MsgBox "Choose the source calendar"Set objCalendarFolderSrc = objNameSpace.PickFolderIf (objCalendarFolderSrc Is Nothing)Then EndWhile objCalendarFolderSrc.DefaultItemType <> olAppointmentItem MsgBox "You did not select a calendar. Try again."Set objCalendarFolderSrc = objNameSpace.PickFolder If (objCalendarFolderSrc Is Nothing)Then EndWendMsgBox "Choose the destination calendar"Set objCalendarFolderDest = objNameSpace.PickFolderIf (objCalendarFolderDest Is Nothing)Then EndWhile objCalendarFolderDest.DefaultItemType <> olAppointmentItem MsgBox "You did not select a calendar. Try again." Set objCalendarFolderDest = objNameSpace.PickFolder If (objCalendarFolderDest Is Nothing) Then End WendSet objItemsSrc = objCalendarFolderSrc.Items Set objItemsDest = objCalendarFolderSrc.ItemsDim x Dim iintMode = 5If objItemsDest.Count < 1 ThenintMode = 4If (intMode = 4) Then For x = 1 To objItemsSrc.Count Set ObjApptsSrc = objItemsSrc.Item(x).Copy ObjApptsSrc.Move objCalendarFolderDest Next End IfIf (intMode = 5) Then For x = 1 To objItemsSrc.Count For i = objItemsDest.Count To 1 Step -1 If objItemsSrc.Item(x).Start = objItemsDest.Item(i).Start Then objItemsDest.Item(i).Delete Set objItemsDest = objCalendarFolderDest.Items End If Next NextFor x = 1 To objItemsSrc.Count Set ObjApptsSrc = objItemsSrc.Item(x).Copy ObjApptsSrc.Move objCalendarFolderDest Next End IfMsgBox "Complete."Set objNameSpace = Nothing Set objOutlook = Nothing Set objCalendarFolderSrc = Nothing Set objCalendarFolderDest = Nothing Set objItemsSrc = Nothing Set objItemsDest = Nothing Set ObjApptsSrc = NothingEnd Sub
Enjoy!