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

[outlook2k3-vba] How to specify a specific contacts folder?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 25th 08, 08:37 AM posted to microsoft.public.outlook.program_vba
news.free.fr
external usenet poster
 
Posts: 6
Default [outlook2k3-vba] How to specify a specific contacts folder?

Dim WithEvents colCTSItems As Items

Private Sub Application_Startup()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
Set colCTSItems = NS.GetDefaultFolder(olFolderContacts).Items

Hi,
I need to specify a contacts folder other than that by default. I do not
know how to make.


thanks

seb


Ads
  #2  
Old July 25th 08, 02:55 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default [outlook2k3-vba] How to specify a specific contacts folder?

How you do that depends on the location of the folder you need. For a
subfolder of Contacts:

Dim oContacts As Outlook.MAPIFolder
Set oContacts = NS.GetDefaultFolder(olFolderContacts)
Dim oSubfolder = oContacts.Folders("Name of folder")
Set colCTSItems = oSubfolder.Items

If the folder is at the top level equal in level to Contacts you'd use
NameSpace.Folders("My folder name")

Otherwise you'd have to iterate the NameSpace.Folders collection, perhaps
recursively if the location could be anywhere until you find the folder with
the name you're looking for.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"news.free.fr" wrote in message
...
Dim WithEvents colCTSItems As Items

Private Sub Application_Startup()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
Set colCTSItems = NS.GetDefaultFolder(olFolderContacts).Items

Hi,
I need to specify a contacts folder other than that by default. I do not
know how to make.


thanks

seb


  #3  
Old July 26th 08, 03:37 PM posted to microsoft.public.outlook.program_vba
seb....
external usenet poster
 
Posts: 1
Default [outlook2k3-vba] How to specify a specific contacts folder?

Thank you for your reply and sorry for my bad english.

I need to adapt the code below to reach a record of contacts appointed
NF_contacts. This folder is located directly under the root folder personnal
folder.

Code:
DimWithEvents colCTSItems As Items
Private Sub Application_Startup ()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace ( "MAPI")
Set colCTSItems = NS.GetDefaultFolder (olFolderContacts). Items
I tried:

Code:
Set colCTSItems = NS.folders ("NF_contacts"). Items
But that does not work, I get an error.




"Ken Slovak - [MVP - Outlook]" a écrit dans le message
de news: ...
How you do that depends on the location of the folder you need. For a
subfolder of Contacts:

Dim oContacts As Outlook.MAPIFolder
Set oContacts = NS.GetDefaultFolder(olFolderContacts)
Dim oSubfolder = oContacts.Folders("Name of folder")
Set colCTSItems = oSubfolder.Items

If the folder is at the top level equal in level to Contacts you'd use
NameSpace.Folders("My folder name")

Otherwise you'd have to iterate the NameSpace.Folders collection, perhaps
recursively if the location could be anywhere until you find the folder
with the name you're looking for.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"news.free.fr" wrote in message
...
Dim WithEvents colCTSItems As Items

Private Sub Application_Startup()
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
Set colCTSItems = NS.GetDefaultFolder(olFolderContacts).Items

Hi,
I need to specify a contacts folder other than that by default. I do not
know how to make.


thanks

seb




  #4  
Old July 26th 08, 06:26 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default [outlook2k3-vba] How to specify a specific contacts folder?

Set colCTSItems = NS.folders ("NF_contacts"). Items

Should work if the folder is named "NF_contacts" and is located directly at
the same level as the default Contacts folder.

What error are you getting?

You might help yourself by splitting that into 2 lines so you can see
exactly where the error occurs:

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"seb...." wrote in message
...
Thank you for your reply and sorry for my bad english.

I need to adapt the code below to reach a record of contacts appointed
NF_contacts. This folder is located directly under the root folder
personnal folder.

Code:
 DimWithEvents colCTSItems As Items
 Private Sub Application_Startup ()
 Dim NS As Outlook.NameSpace
 Set NS = Application.GetNamespace ( "MAPI")
 Set colCTSItems = NS.GetDefaultFolder (olFolderContacts). Items

I tried:

Code:
 Set colCTSItems = NS.folders ("NF_contacts"). Items

But that does not work, I get an error.


  #5  
Old July 27th 08, 12:11 PM posted to microsoft.public.outlook.program_vba
news.free.fr
external usenet poster
 
Posts: 6
Default [outlook2k3-vba] How to specify a specific contacts folder?

I have this error :

Operation cannot carry out. Am not possible carry one out to find an object.
Error of execution '-2147221233 (8004010f)

when i use :

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items

I have error at line
Set oFolder = NS.folders ("NF_contacts")

I assume that it does not find the file while this one exists.


"Ken Slovak - [MVP - Outlook]" a écrit dans le message
de news: ...
Set colCTSItems = NS.folders ("NF_contacts"). Items

Should work if the folder is named "NF_contacts" and is located directly
at the same level as the default Contacts folder.

What error are you getting?

You might help yourself by splitting that into 2 lines so you can see
exactly where the error occurs:

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"seb...." wrote in message
...
Thank you for your reply and sorry for my bad english.

I need to adapt the code below to reach a record of contacts appointed
NF_contacts. This folder is located directly under the root folder
personnal folder.

Code:
 DimWithEvents colCTSItems As Items
 Private Sub Application_Startup ()
 Dim NS As Outlook.NameSpace
 Set NS = Application.GetNamespace ( "MAPI")
 Set colCTSItems = NS.GetDefaultFolder (olFolderContacts). Items

I tried:

Code:
 Set colCTSItems = NS.folders ("NF_contacts"). Items

But that does not work, I get an error.




  #6  
Old July 27th 08, 09:57 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default [outlook2k3-vba] How to specify a specific contacts folder?

OK, that error is MAPI_E_NOT_FOUND.

So the question is if that folder is in your default PST file, and if you
have more than one PST file open.

Where is this code running, in Outlook VBA or somewhere else?

Let's try a round-about method of trying to get at that folder. Assuming
it's in the default PST, let's try getting a default folder then the parent
of that default folder and then the target folder.

So try this, assuming this is Outlook VBA code:
Dim NS As Outlook.NameSpace
Dim oInbox As Outlook.MAPIFolder
Dim oFolder As Outlook.MAPIFolder
Dim oParent As Outlook.MAPIFolder

' next line only works in Outlook VBA where Application is Outlook
Set NS = Application.GetNameSpace("MAPI")
Set oInbox = NS.GetDefaultFolder(olFolderInbox)
Set oParent = oInbox.Parent
Set oFolder = oParent.Folders ("NF_contacts")
Set colCTSItems = oFolder. Items

See if that works or where you get an error.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"news.free.fr" wrote in message
...
I have this error :

Operation cannot carry out. Am not possible carry one out to find an
object.
Error of execution '-2147221233 (8004010f)

when i use :

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items

I have error at line
Set oFolder = NS.folders ("NF_contacts")

I assume that it does not find the file while this one exists.


  #7  
Old July 27th 08, 10:41 PM posted to microsoft.public.outlook.program_vba
news.free.fr
external usenet poster
 
Posts: 6
Default [outlook2k3-vba] How to specify a specific contacts folder?

Hi,

I found the solution

Set NS = Application.GetNamespace("MAPI")
Set oFolder = NS.Folders("LastName Firstname").Folders("NF_contacts")
Set colCTSItems = oFolder.Items



"news.free.fr" a écrit dans le message de news:
...
I have this error :

Operation cannot carry out. Am not possible carry one out to find an
object.
Error of execution '-2147221233 (8004010f)

when i use :

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items

I have error at line
Set oFolder = NS.folders ("NF_contacts")

I assume that it does not find the file while this one exists.


"Ken Slovak - [MVP - Outlook]" a écrit dans le
message de news: ...
Set colCTSItems = NS.folders ("NF_contacts"). Items

Should work if the folder is named "NF_contacts" and is located directly
at the same level as the default Contacts folder.

What error are you getting?

You might help yourself by splitting that into 2 lines so you can see
exactly where the error occurs:

Dim oFolder As Outlook.MAPIFolder
Set oFolder = NS.folders ("NF_contacts")
Set colCTSItems = oFolder. Items


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"seb...." wrote in message
...
Thank you for your reply and sorry for my bad english.

I need to adapt the code below to reach a record of contacts appointed
NF_contacts. This folder is located directly under the root folder
personnal folder.

Code:
 DimWithEvents colCTSItems As Items
 Private Sub Application_Startup ()
 Dim NS As Outlook.NameSpace
 Set NS = Application.GetNamespace ( "MAPI")
 Set colCTSItems = NS.GetDefaultFolder (olFolderContacts). Items

I tried:

Code:
 Set colCTSItems = NS.folders ("NF_contacts"). Items

But that does not work, I get an error.






  #8  
Old July 28th 08, 03:06 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default [outlook2k3-vba] How to specify a specific contacts folder?

OK, so the folder wasn't actually at the same level as the default Contacts
folder, it's a subfolder of your "LastName Firstname" folder. That explains
your problems.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"news.free.fr" wrote in message
...
Hi,

I found the solution

Set NS = Application.GetNamespace("MAPI")
Set oFolder = NS.Folders("LastName Firstname").Folders("NF_contacts")
Set colCTSItems = oFolder.Items


  #9  
Old July 28th 08, 11:13 PM posted to microsoft.public.outlook.program_vba
news.free.fr
external usenet poster
 
Posts: 6
Default [outlook2k3-vba] How to specify a specific contacts folder?

Yes, the case is not a subfolder of contact folder by default.

Now, I try to test if the file exists and create it if it does not exist.


"Ken Slovak - [MVP - Outlook]" a écrit dans le message
de groupe de discussion : ...
OK, so the folder wasn't actually at the same level as the default
Contacts folder, it's a subfolder of your "LastName Firstname" folder.
That explains your problems.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"news.free.fr" wrote in message
...
Hi,

I found the solution

Set NS = Application.GetNamespace("MAPI")
Set oFolder = NS.Folders("LastName Firstname").Folders("NF_contacts")
Set colCTSItems = oFolder.Items


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Move email from specific folder (under the inbox) to a specific fo Emil Outlook and VBA 3 June 15th 08 07:23 PM
Outlook2k3 not autosending or downloading jmillerWV Outlook - Installation 1 June 19th 07 03:23 PM
How Can I change the Default Calendar in Outlook2k3? Joecool Outlook - Calandaring 2 July 21st 06 11:15 PM
Please help me to add my contacts from emails to specific contact folder [email protected] Outlook - Using Contacts 1 June 28th 06 03:09 PM
Please help me to add my contacts from emails to specific contact folder [email protected] Outlook - Using Contacts 0 June 28th 06 02:47 PM


All times are GMT +1. The time now is 08:57 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.