Skip to main content

Sync Outlook/Hotmail Calender into a local calender as a backup using VBA.

Problem:


Sync Outlook/Hot-mail Calender into a local calender as a backup using VBA.

Solution:

1.) Open your outlook window..


2.) Press Alt+F11 Key from Keyboard.


3) Past the code and save it.

Dim WithEvents newCal As Items

Private Sub Application_Startup()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
Set newCal = NS.GetDefaultFolder(olFolderCalendar).Items
Set NS = Nothing
End Sub

Private Sub newCal_ItemAdd(ByVal Item As Object)
Dim cAppt As AppointmentItem
Dim moveCal as AppointmentItem
On Error Resume Next
Set CalFolder = GetFolderPath("display name in folder list\Calendar\Test")

If Item.BusyStatus = olBusy Then

Set cAppt = Application.CreateItem(olAppointmentItem)

With cAppt
.Subject = "Copied: " & Item.Subject
.Start = Item.Start
.Duration = Item.Duration
.Location = Item.Location
.Body = Item.Body
.Save
End With

' set the category after it's moved to force EAS to sync changes
Set moveCal = cAppt.Move(CalFolder)
moveCal.Categories = "moved"
moveCal.Save

End If
End Sub


Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer

On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function

GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function


Note:If you are not sure about the VBA Write me an email for steps.

Comments

Popular posts from this blog

Office 2013 Error "Microsoft Word has stopped working".

Problem: Office 2013 Error "Microsoft Word has stopped working". Cause: This issue could in office 2013. 1.) Abby Fine Reader 2.) Graphic Card Driver. 3) Any Third Party Addin. Solution: Method 1: 1) Look for Abbyy Fine reader in control panel. 2)Remove it from the program list. 3)Restart the computer and check the status. If you are not able to remove it update the latest Update for Abbyy Fine Reader from their website. Method 2: 1) Try to disable Graphic adapter from Device manager Locate Device Manager: Right Click on My computer-->Properties -->Device Manager. 2) Open office application. 3)Check the status. Method 3: 1)Open any office application. 2)Open file-->options--Advance. 3)Disable Hardware Acceleration. Method 4: 1)Open Event Viewer by Run Window(Crtl+R) 2) Type eventvwr.msc and look for the office error. 3) Look for faulting module and rename the file from the file location. 4) Open office application and

Setup cannot find office.en-us\dwtrig20.exe during office installation

Problem:  Setup cannot find office.en-us\dwtrig20.exe during office installation Solution: Method 1 : a) Uninstall skype form control panel. b) After installing office, re-install skype. Method 2: a) Browse disk by right clicking on it with mouse. b) Double click on setup.exe file from the same location. Method 3: Note: Take backup of your registry before modifying it.  For registry backup: open "run" >> type "regedit" >> goto "file" >> click on "export" on desktop. a) Edit the registry. HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > OFFICE Delete the keys (items) you find in the OFFICE folder but not the sub-folders. This removes traces of previous installs to avoid possible conflicts when installing the new version of Office. b)HKEY_LOCAL_MACHINE > SOFTWARE > MICROSOFT > OFFICE > DELIVERY > SOURCEENGINE > DOWNLOADS Delete the keys (items) you find here.

Error can't display online services while signing into Microsoft Account in office 2013.

Problem: Error can't display online services while signing into Microsoft Account in office 2013. Solution:     Method 1: Open any Office Application, go to File > Account Under "User Information", select Sign Out Restart Windows Open Office Application, go to File > Account > Sign In Method 2: Login into Login.live.com Update your information(Complete profile) Signout from Microsoft Account and Reboot the computer. Try Again.