![]() |
[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 |
[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 |
[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 I tried: Code:
Set colCTSItems = NS.folders ("NF_contacts"). Items But that does not work, I get an error. |
[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 I tried: Code:
Set colCTSItems = NS.folders ("NF_contacts"). Items But that does not work, I get an error. |
[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. |
[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 I tried: Code:
Set colCTSItems = NS.folders ("NF_contacts"). Items But that does not work, I get an error. |
[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 |
[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 |
All times are GMT +1. The time now is 12:34 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com