'Import Outlook Calendar Appointment from One account to another in Python/VBA
Actually I am trying to Export the calendar appointment from one outlook account to another outlook account but I have trayed so many time and end-up with just extracted appointment in an excel sheet and importing the same into another account. I don't have to much knowledge of VBA but I have used via internet and got this -
Private Sub Outlook_Vba_Get_Calendar_Item_Appoinments()
Dim oWorkbook As Workbook, Calendar_To_Excel_File As String
Dim oOutlook_Calendar As Outlook.Folder, oCalendar_Items As Outlook.Items
Dim oCalendarAppointment As Outlook.AppointmentItem
Dim iRow As Double
iRow = 1
'Change path of the Target File name if required
Calendar_To_Excel_File = "D:\Sample23434.xlsx"
'Check if Output File already exists
If VBA.Dir(Calendar_To_Excel_File) = "" Then
'To Create New Workbook
Set oWorkbook = Workbooks.Add
oWorkbook.SaveAs Calendar_To_Excel_File
Else
'To Refer Already Created Workbook
Set oWorkbook = Workbooks.Open(Calendar_To_Excel_File)
End If
'Get object reference for Outlook Calendar folder
Set oOutlook_Calendar = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)
Set oCalendar_Items = oOutlook_Calendar.Items
'Loop Thru Each Items in Outlook Calendar
For Each oCalendarAppointment In oCalendar_Items
oWorkbook.Sheets(1).Cells(iRow, 1) = oOutlook_Calendar.FolderPath
oWorkbook.Sheets(1).Cells(iRow, 2) = oCalendarAppointment.Start
oWorkbook.Sheets(1).Cells(iRow, 3) = oCalendarAppointment.End
oWorkbook.Sheets(1).Cells(iRow, 4) = oCalendarAppointment.Subject
oWorkbook.Sheets(1).Cells(iRow, 5) = oCalendarAppointment.Location
oWorkbook.Sheets(1).Cells(iRow, 6) = oCalendarAppointment.Duration
oWorkbook.Sheets(1).Cells(iRow, 7) = oCalendarAppointment.Size
'oWorkbook.Sheets(1).Cells(irow, 8) = oCalendarAppointment.Body
iRow = iRow + 1
Next
'Save Excel Workbook With Calendar Appointments
oWorkbook.Save
oWorkbook.Close False 'Close Workbook without any Warning
MsgBox "Outlook Calendar Appointments Downloaded To:" & Calendar_To_Excel_File
End Sub
If any one know how can I do this without using Excel please let me know with either Python or VBA
Solution 1:[1]
If you have got another account shared by a user (or just a calendar with required permissions to modify it) you could add a shared calendar to the Outlook profile and copy/move the required appointments directly without involving Excel workbooks for that.
The NameSpace.GetSharedDefaultFolder method returns a Folder object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder). For example, here is how you could use it to get the shared calendar folder in Outlook:
Sub ResolveName()
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
Dim CalendarFolder As Outlook.Folder
Set myNamespace = Application.GetNamespace("MAPI")
Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev")
myRecipient.Resolve
If myRecipient.Resolved Then
Call ShowCalendar(myNamespace, myRecipient)
End If
End Sub
Sub ShowCalendar(myNamespace, myRecipient)
Dim CalendarFolder As Outlook.Folder
Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar)
CalendarFolder.Display
End Sub
After retrieving the target folder instance you can use the AppointmentItem.Move or AppointmentItem.CopyTo methods.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Astafiev |
