A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: , , , ,

Adding appointment to non default calendar





 
 
Thread Tools Display Modes
  #1  
Old June 13th 07, 03:00 PM posted to microsoft.public.outlook.program_vba
Andy Pope
external usenet poster
 
Posts: 5
Default Adding appointment to non default calendar

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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Ads
  #2  
Old June 13th 07, 04:10 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,779
Default Adding appointment to non default calendar

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Andy Pope" wrote in message
...
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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


  #3  
Old June 13th 07, 04:34 PM posted to microsoft.public.outlook.program_vba
Andy Pope
external usenet poster
 
Posts: 5
Default Adding appointment to non default calendar

Hi Ken,

Here are the Error details


--

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

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Andy Pope" wrote in message
...
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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



  #4  
Old June 13th 07, 04:42 PM posted to microsoft.public.outlook.program_vba
Andy Pope
external usenet poster
 
Posts: 5
Default Adding appointment to non default calendar

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 - [MVP - Outlook]" wrote in message
...
Where is Calendar21 located? Is it directly under the default calendar
folder? The code should work if it is. What error are you getting?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Andy Pope" wrote in message
...
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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info



  #5  
Old June 13th 07, 04:58 PM posted to microsoft.public.outlook.program_vba
Andy Pope
external usenet poster
 
Posts: 5
Default Adding appointment to non default calendar

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" wrote in message
...
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 - [MVP - Outlook]" wrote in message
...
Where is Calendar21 located? Is it directly under the default calendar
folder? The code should work if it is. What error are you getting?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Andy Pope" wrote in message
...
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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info




  #6  
Old June 14th 07, 04:48 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,779
Default Adding appointment to non default calendar

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Andy Pope" wrote in message
...
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


  #7  
Old June 14th 07, 09:18 PM posted to microsoft.public.outlook.program_vba
Andy Pope
external usenet poster
 
Posts: 5
Default Adding appointment to non default calendar

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

Ken Slovak - [MVP - Outlook] wrote:
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.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create an appointment item in a non-default calendar Jennifer Outlook and VBA 4 June 20th 07 05:39 PM
Adding cc field to an appointment JaneH Outlook - Calandaring 2 February 28th 07 09:29 PM
Changing Calendar Appointment default. Rita Outlook - Calandaring 1 June 7th 06 11:17 PM
Adding "non-appointment" emails to calendar with the click of a bu superjacked Outlook - Calandaring 1 April 12th 06 07:35 PM
How to set Outlook calendar appointment reminder to default 1 hr? Wan G Outlook - Calandaring 1 February 9th 06 05:10 PM


All times are GMT +1. The time now is 05:56 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2008 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
Online Advertising - Babb Fest - Problem Mortgage - Remortgages - Credit Cards UK