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.

We're sorry, but Excel has run into an error that is preventing it from working correctly. Excel will need to be closed as a result. Would you like us to repair it now?

Issue: We're sorry, but Excel has run into an error that is preventing it from working correctly. Excel will need to be closed as a result. Would you like us to repair it now? This error occur due to some compatibility with the older version office installation. 1.        Go to C:\Program Files (x86)\Microsoft Office\Office15, look for EXCEL.EXE 2.       Right Click on this, Properties, In Compatibility tab, check ""Run this Program as an Administrator" 3.       Start the Excel. You might again get the error. Close Exel and uncheck ""Run this Program as an Administrator"". Start Exel again. You should not get the error anymore. 4.       File > Options > Advanced - In General section (go very much down in Advanced), check ""Ignore Other applications that use Dynamic Data Exchange (DDE)"". Close and re-start the Excel. Uncheck ""Ignore Other applications tha...