paul.robinson@it-tallaght.ie
Guest
Re: Is it possible to create distribution list for Outlook?
Hi John
This will create a new subfolder of your Contacts folder. That SEEMS to
be what you are asking for, rather than a distribution list (which I
don't know how to do!)
Public Sub MakeContactsFolders(FolderName As String)
Dim olApplication as OutLook.Application
Dim olNameSpace as OutLook.NameSpace
Dim objFolder As MAPIFolder, objNewFolder As MAPIFolder
Dim objContact As Outlook.ContactItem
Application.ScreenUpdating = False
Set olApplication = CreateObject("Outlook.Application")
Set olNameSpace = olApplication.GetNameSpace("MAPI")
'create a new contacts folder in the Contacts Folder
'you might need to delete it first if it already exists
'****optional code
Set objFolder = olNameSpace.GetDefaultFolder(olFolderContacts)
On Error Resume Next 'see if FolderName exists
Set objNewFolder = objFolder.Folders(FolderName)
On Error GoTo 0
'If folder already exists delete it
If Not objNewFolder Is Nothing Then objNewFolder.Delete
'***end of optional code
Set objNewFolder = objFolder.Folders.Add(FolderName,
olFolderContacts)
'Add some contact info to the created folder
'If using a loop here, need fresh Set objContact for each contact
Set objContact = objNewFolder.Items.Add(olContactItem)
With objContact
'Add some address info
End With
'end loop structure if using one
objNewFolder.ShowAsOutlookAB = True 'see it in addressbook
Set objContact = Nothing
Set objNewFolder = Nothing
Set objFolder = Nothing 'contacts folder
Set olNameSpace = Nothing
Set olApplication = Nothing
End Sub
be careful with line breaks
regards
Paul
John Elink wrote:
> Hi there
>
> I have Excel file with names (1st column) and e-mail addresses (2nd
> column). If I want to add all these names into the Outlook's Contact
> list, there is no problem. I use something like as follows
> *********************
> Set olApplication = CreateObject("Outlook.Application")
> Set olNameSpace = olApplication.GetNameSpace("MAPI")
> Set olContactFolder =
> olNameSpace.GetDefaultFolder(olFolderContacts)
> Set olContactItem = olContactFolder.Items.Add
> With olContactItem
> .LastName = *****here I read from file
> .Email1Address = *****here I read from file
> .Save
> End With
> **********************
> it creates new item in Contact.
>
> My question is - is it possible to create NEW DISTRIBUTION LIST using
> macro? I mean all names/e-mail addresses from the Excel file will be
> stored in the new distribution list in Outlook, so these new contacts
> will not be mixed with my "normal" contacts
>
> Thank you very much for all comments.
>
> Cheers
> Johny
Bookmarks