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

How to display the location of the current file on the Quick Access Toolbar in Office 2013

 Problem  How to display the location of the current file on the Quick Access Toolbar in Office 2013 Solution You can display the location of the currently open Office document on the Quick Access Toolbar. To do this follow these steps: 1. Open any document or a blank document in Word and click the FILE tab. 2. Click Options at the bottom of the options list on the left. 3. On the Word Options dialog box, click Quick Access Toolbar in the options list on the left. 4. To narrow the choices in the list of commands and make it quicker to find the desired option, select Commands Not in the Ribbon from the Choose commands from drop-down list. 5. Scroll down in the list of commands until you find the Document Location command. Select it and click Add to add it to the Quick Access Toolbar. You can move the Document Location command to a different location on the Quick Access Toolbar using the up and down arrows to the right of the list of toolbar commands. 6. Click OK to accept the c...

How to send email force fully using a default account in outlook.

Problem: How to send email force fully using a default account in outlook. Solution: People who use multiple accounts and frequently (accidentally) send using the wrong account, especially if they are sending sensitive documents, as it will almost eliminate accidentally sending email from the wrong account. In Outlook 2010, the registry key is: HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\14.0\outlook\options Value Name: ForceAccountSelection Value type: REG_DWORD: 1 for force, 0 to disable. In Outlook 2013, the registry key is: HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\15.0\outlook\options Value Name: ForceAccountSelection Value type: REG_DWORD: 1 for force, 0 to disable. Notes: You need to create the path if it does not exist. The value type is the same for both 32-bit and 64-bit Outlook.

How to change the color of the wavy underline that indicates spelling errors.?

Issue: How to change the color of the wavy underline that indicates spelling errors.? Solution: To change the color of the wavy underline that indicates spelling errors, follow these steps: 1.      Click Start , click Run , type regedit , and then click OK . 2.      Locate and then click the following registry subkey: HKEY_CURRENT_USER\Software\Microsoft\Shared Tools\Proofing Tools 3.      If the SpellingWavyUnderlineColor entry exists, go to step 6. If the SpellingWavyUnderlineColor entry does not exist, go to step 4. 4.      On the Edit menu, point to New , and then click DWORD Value . 5.      In the right pane, type SpellingWavyUnderlineColor . This is the name of the new entry. 6.      In the right pane, double-click SpellingWavyUnderlineColor . 7.      In the Edit DWORD Value dialog box, click Hexadecimal . 8.      In th...