Using Word VBA to Create Appointment Items in Outlook
Your code sets appOL as an Outlook.Application object. Therefore, this is
the object you need to use with the CreateItem method:
Set itemCalendar = appOL.CreateItem(1)
If you're working with your default Calendar folder, you do not need to use
the Items.Add method.
Sue Mosher, Outlook MVP
Teach Yourself Microsoft Outlook 2000 Programming in 24 Hours
Microsoft Outlook 2000 E-mail and Fax Guide
Outlook and Exchange solutions at http://www.slipstick.com
> I have the following code to add a record to my Outlook calendar, save
> it, and then close Outlook. Unfortunately, it fails since I don't know
> how to create a new Outlook appointment item.
> I am using Word 2000 and Outlook 2000.
> Here is the Code:
> Sub OutlookTest()
> Dim appOL As Outlook.Application
> Dim nmsNameSpace As Outlook.NameSpace
> Dim fldCalendar As Outlook.MAPIFolder
> Dim itemCalendar As Outlook.AppointmentItem
> Dim ItemsCal As Outlook.Items
> Set appOL = CreateObject("outlook.application")
> Set nmsNameSpace = appOL.GetNamespace("MAPI")
> Set fldCalendar = nmsNameSpace.GetDefaultFolder(olFolderCalendar)
> 'THE CODE FAILS HERE, THAT IS, IN CREATING THE OUTLOOK APPOINTMENT ITEM!
> 'Set itemCalendar = outlook.CreateItem (
> 'Set itemCalendar = Application.CreateItem(1) 'Create appointmentitem
> Set itemCalendar = ItemsCal.Add("IPM.AppointmentItem")
> With itemCalendar
> .Categories = "Test"
> .start = Now
> .AllDayEvent = True
> .Subject = "This is a test done " & Now
> End With
> End Sub
> 'Set itemCalendar = Nothing
> 'Set fldCalendar = Nothing
> 'Set nmsNameSpace = Nothing
> 'Set appOL
> Thank you!