PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Adding a distribution list to my own contacts folder.
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Adding a distribution list to my own contacts folder.
![]() |
Adding a distribution list to my own contacts folder. |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi,
I have successfully managed to create contacts and put them in into a distribution list. I have modified this to create the contacts in my own contacts, (not the root default contacts folder). How do I know create a distribution list in the new contacts folder? The current code creates the dist list in the root contact folder and a move is attempted. This just leaves me with two dist lists which are both empty. Thanks in advance. Neil **START CODE** var objOutlook = new ActiveXObject("Outlook.Application") var objOutlookMsg = objOutlook.CreateItemFromTemplate(this.templatePath); var objTempItem = objOutlook.CreateItem(olMailItem); var objContact var objRecipients = objTempItem.Recipients; var objDistList = objOutlook.CreateItem(olDistributionListItem); objDistList.DLName = GROUPNAME; var objNamespace = objOutlook.GetNamespace('MAPI'); var objFolder = objNamespace.GetDefaultFolder(olFolderContacts); var objNewFolder = objFolder.Folders.Add(GROUPNAME); var objContact = objNewFolder.items.add(); //objDistList.parent = objNewFolder; //var objDistList = objNewFolder.Folders.add('test', olDistributionListItem); var record; var email; var objContact; for (var i=0;i<nodeList.length;i++) { record = nodeList[i]; email = record.getAttribute('emailaddress'); //objContact = objOutlook.CreateItem(olContactItem); //objContact = objNewFolder.items.add(); objContact.email1address = email; objContact.FileAs = objContact.email1address; objContact.Save(); objRecipients.add(objContact.email1address); } objRecipients.ResolveAll(); objDistList.AddMembers(objRecipients); objDistList.Save(); objOutlookMsg.Subject = this.subject; //objOutlookMsg.Body = objOutlookMsg.Importance = olImportanceNormal; var objRecipient = objOutlookMsg.Recipients.Add(objDistList.DLName); objRecipient.Type = olBCC; objRecipient.Resolve(); objOutlookMsg.Save(); //Save mail to draft folder. You can call save method to send the email **END CODE** |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Use the Add method on the target folder's Items collection.
-- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx <neilsg2001@yahoo.co.uk> wrote in message news:1110204667.957211.158730@f14g2000cwb.googlegroups.com... > Hi, > > I have successfully managed to create contacts and put them in into a > distribution list. I have modified this to create the contacts in my > own contacts, (not the root default contacts folder). How do I know > create a distribution list in the new contacts folder? > > The current code creates the dist list in the root contact folder and a > move is attempted. This just leaves me with two dist lists which are > both empty. > > Thanks in advance. > > Neil > > **START CODE** > var objOutlook = new ActiveXObject("Outlook.Application") > var objOutlookMsg = > objOutlook.CreateItemFromTemplate(this.templatePath); > var objTempItem = objOutlook.CreateItem(olMailItem); > var objContact > var objRecipients = objTempItem.Recipients; > var objDistList = objOutlook.CreateItem(olDistributionListItem); > objDistList.DLName = GROUPNAME; > > var objNamespace = objOutlook.GetNamespace('MAPI'); > var objFolder = objNamespace.GetDefaultFolder(olFolderContacts); > var objNewFolder = objFolder.Folders.Add(GROUPNAME); > var objContact = objNewFolder.items.add(); > //objDistList.parent = objNewFolder; > //var objDistList = objNewFolder.Folders.add('test', > olDistributionListItem); > > var record; > var email; > var objContact; > for (var i=0;i<nodeList.length;i++) > { > record = nodeList[i]; > email = record.getAttribute('emailaddress'); > > //objContact = objOutlook.CreateItem(olContactItem); > //objContact = objNewFolder.items.add(); > objContact.email1address = email; > objContact.FileAs = objContact.email1address; > objContact.Save(); > > objRecipients.add(objContact.email1address); > } > > objRecipients.ResolveAll(); > objDistList.AddMembers(objRecipients); > > objDistList.Save(); > > objOutlookMsg.Subject = this.subject; > //objOutlookMsg.Body = > objOutlookMsg.Importance = olImportanceNormal; > > var objRecipient = objOutlookMsg.Recipients.Add(objDistList.DLName); > objRecipient.Type = olBCC; > objRecipient.Resolve(); > > objOutlookMsg.Save(); //Save mail to draft folder. You can call > save method to send the email > **END CODE** > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks Sue,
Now i have my contacts in a dist list in the sub contacts folder where I want them. When i try to use the dist list for the to or bcc field of an email, neither the contact folder or distlist is available or valid??!! Neil |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Did you check the box on the Properties dialog of the folder that exposes
that folder through the Outlook Address Book? -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Neil" <neilsg2001@yahoo.co.uk> wrote in message news:1110274269.114640.113860@l41g2000cwc.googlegroups.com... > Thanks Sue, > > Now i have my contacts in a dist list in the sub contacts folder where > I want them. > > When i try to use the dist list for the to or bcc field of an email, > neither the contact folder or distlist is available or valid??!! > > > Neil > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks.
myMapiFolder.ShowAsOutlookAB = true outlook 2002 onwards only - damn ![]() Maybe i'll just put the email addresses in a distribution list in the root contacts folder and then delete any contacts required to do this afterwards. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


