Adding appointment to non default calendar

A

Andy Pope

Hi,

I have OL 2007 with 2 calendars. The default and a new one I named
Calendar21. (This is not a shared calendar, if that makes a difference)

With VBA, which I run from Excel, I am trying to create a reference to
Calendar21 and add an appointment.
The following code fails at the line marker '<<<<
What code should I be using to locate and create a reference to required
calendar?

'-------
Dim objOL As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder1 As Outlook.Folder
Dim olFolder2 As Outlook.Folder
Dim objItem As Outlook.AppointmentItem
Dim lngRow As Long

Set objOL = CreateObject("Outlook.Application")
Set olNS = objOL.GetNamespace("MAPI")

Set olFolder1 = olNS.GetDefaultFolder(olFolderCalendar)
Set olFolder2 = olFolder1.Folders("Calendar21") '<<<<
'-------

I have no problem adding items to the default calendar.

Any insight greatly received.

Cheers
Andy
 
K

Ken Slovak - [MVP - Outlook]

Where is Calendar21 located? Is it directly under the default calendar
folder? The code should work if it is. What error are you getting?
 
A

Andy Pope

Hi Ken, (excuse previous half post. FatFingerSyndrome)

Error code information
-2147221233
The operation failed. An object could not be found.

When I use the menu Go > Folders (CTRL+6) I do not see additional calendar.
But I the Calendar section of the Navigation pane, within the My Calendars
section the 2 calendars are listed.

When I do a folder count of the returned default calendar folder I get 0
(zero)

Cheers
Andy
--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Ken Slovak - said:
Where is Calendar21 located? Is it directly under the default calendar
folder? The code should work if it is. What error are you getting?
 
A

Andy Pope

More info....

I tried adding a New calendar and this DOES appear as a folder item and I
can loop through the .Folders collection and locate it.
I'm now doubting my sanity about how I created the other calendar which I
can not see.

But I still have the problem of adding an appointment item to a specific
calendar as the current code adds the appointment to the Outlook application
rather than a specific calendar.

Set objItem = objOL.CreateItem(olAppointmentItem)

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
Andy Pope said:
Hi Ken, (excuse previous half post. FatFingerSyndrome)

Error code information
-2147221233
The operation failed. An object could not be found.

When I use the menu Go > Folders (CTRL+6) I do not see additional
calendar.
But I the Calendar section of the Navigation pane, within the My Calendars
section the 2 calendars are listed.

When I do a folder count of the returned default calendar folder I get 0
(zero)

Cheers
Andy
 
K

Ken Slovak - [MVP - Outlook]

Are you positive the problem calendar is really in the same store (PST file
or Exchange mailbox) as the default calendar? It sounds to me like it's in a
different store.

If it's a different store than you can iterate the NameSpace.Folders
collection. Each top level folder there is a different store and you can
then iterate that store to find a specific folder. If you are using Outlook
2007 it's even easier, any loaded store is in the Stores collection.

To add an item to a specific folder instead of the default folder for that
type of item use the Folder.Items.Add method instead of CreateItem. That
always places items in the default folder for that type of item.
 
A

Andy Pope

Hi Ken,

I guess it was not.
I deleted it and added a calendar sub folder to my default calendar and
all the code worked as expected.

Thanks for taking the time to help with my problem.

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top