I want to create calendar entries in a non-default calendar in Outlook via python. I did
import win32com.client
outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI')
calendar = outlook.Folders('myaccount@mail.com').Folders('calendar').Folders('subcalendar')
I can read entries, count entries of the subcalendar - all good. Now I try to create a new item in this 'subcalendar' by
newapp = calendar.CreateItem(win32com.client.constants.olAppointmentItem)
newapp.Start = '2020-09-25 08:00'
newapp.Subject = 'Testentry'
newapp.Duration = 15
newapp.Save()
but it's throwing an exception: AttributeError
: <unknown>.CreateItem
.
I am calling the object 'subcalendar' with the method CreateItem
and the correct object type...
You can use the following code:
newapp = calendar.Items.Add()
newapp.Start = '2020-09-25 08:00'
newapp.Subject = 'Testentry'
newapp.Duration = 15
newapp.Save()
The Items.Add method creates a new Outlook item in the Items
collection for the folder. If the type is not specified, the Type
property of the Outlook item defaults to the type of the folder or to MailItem
if the parent folder is not typed.
You may find the How To: Create a new Outlook Appointment item article helpful.