Home > Uncategorized > #Exchange #Outlook Create a Local Distribution List from Email using script

#Exchange #Outlook Create a Local Distribution List from Email using script


Nice Script I found on EE thought that I would share, the script reads the recipients from an email message and then prompts you add CC guys to the DL and create the DL.

Sub MakeDistListFromMsg()
    Const MACRONAME = "Make Distribution List from Message"
    Dim olkItem As Object, _
        olkDistList As Outlook.DistListItem, _
        olkRecipient As Outlook.Recipient, _
        olkFolder As Outlook.MAPIFolder, _
        bolCC As Boolean, _
        bolBCC As Boolean
    Select Case TypeName(Application.ActiveWindow)
        Case "Explorer"
            Set olkItem = Application.ActiveExplorer.Selection(1)
        Case "Inspector"
            Set olkItem = Application.ActiveInspector.CurrentItem
    End Select
    Set olkDistList = Application.CreateItem(olDistributionListItem)
    If MsgBox("Do you want to include CC addressees?", vbQuestion + vbYesNo, MACRONAME) = vbYes Then bolCC = True
    If MsgBox("Do you want to include BCC addressees?", vbQuestion + vbYesNo, MACRONAME) = vbYes Then bolBCC = True
    For Each olkRecipient In olkItem.Recipients
        Select Case olkRecipient.Type
            Case olTo
                olkDistList.AddMember olkRecipient
            Case olCC
                If bolCC Then olkDistList.AddMember olkRecipient
            Case olBCC
                If bolBCC Then olkDistList.AddMember olkRecipient
        End Select
    Next
    Do While olkDistList.Subject = ""
        olkDistList.Subject = InputBox("You must give the distribution list a name.", "Make Distribution List from Message")
    Loop
    olkDistList.Save
    Set olkFolder = Session.PickFolder
    If olkFolder.DefaultItemType = olContactItem Then
        olkDistList.Move olkFolder
    Else
        MsgBox "You didn't pick a Contacts folder.  The list was saved in your default Contacts folder instead.", vbExclamation + vbOKOnly, MACRONAME
    End If
    Set olkItem = Nothing
    Set olkDistList = Nothing
    Set olkRecipient = Nothing
    Set olkFolder = Nothing
End Sub
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: