Hi - I manage a DL in my company's global address book. People e-mail me to add them to the DL. Manually you can do this in the global address book by right-clicking on the DL and modifying members and adding a contact. I only have a code that can add a sender's email address (although it's taking all addresses but mine) to a group in my private contacts. Is there a way to build a code that when someone asks to be added to the DL via email I can run the macro so that it adds the sender's email (FROM field only, not TO or CC) to the global address book DL (GDL - GROUPNAME). Thanks!
The code I have been using is as follows:
Sub UpdateDistListItem()
'Create some constants
'On the next line enter the name of the list the script is to update.
Const LIST_NAME = "EXAMPLE"
'Create some variables
Dim olkItm As Object, olkRcp As Outlook.Recipient, olkLst As Outlook.DistListItem
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set olkItm = Application.ActiveExplorer.Selection(1)
Case "Inspector"
Set olkItm = Application.ActiveInspector.CurrentItem
End Select
If TypeName(olkItm) <> "Nothing" Then
Select Case olkItm.Class
'If the source item is an email or appointment
Case olMail, olAppointment
'Find the distribution list to update
Set olkLst = Session.GetDefaultFolder(olFolderContacts).Items.Find("[Name] = '" & LIST_NAME & "'")
If TypeName(olkLst) = "Nothing" Then
MsgBox "I could not find a distribution list named '" & LIST_NAME & "'.", vbCritical + vbOKOnly, "Operation Cancelled "
Else
With olkLst
'If the source item is an email, then add the sender
If olkItm.Class = olMail Then
Set olkRcp = Session.CreateRecipient(olkItm.SenderEmailAddress)
olkRcp.Resolve
.AddMember olkRcp
End If
'Loop through the recipients of the source item
For Each olkRcp In olkItm.Recipients
'If the recipient is not the current user
If olkRcp.Name <> Session.CurrentUser.Name Then
'If the source item an email or if it is an appointment and the recipient is not a resource
If (olkItm.Class = olMail) Or (olkItm.Class = olAppointment And olkRcp.Type <> olResource) Then
'Add the recipient to the list
.AddMember olkRcp
End If
End If
DoEvents
Next
.Display
End With
End If
End Select
End If
Set olkItm = Nothing
Set olkRcp = Nothing
Set olkLst = Nothing
End Sub
The code I have been using is as follows:
Sub UpdateDistListItem()
'Create some constants
'On the next line enter the name of the list the script is to update.
Const LIST_NAME = "EXAMPLE"
'Create some variables
Dim olkItm As Object, olkRcp As Outlook.Recipient, olkLst As Outlook.DistListItem
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set olkItm = Application.ActiveExplorer.Selection(1)
Case "Inspector"
Set olkItm = Application.ActiveInspector.CurrentItem
End Select
If TypeName(olkItm) <> "Nothing" Then
Select Case olkItm.Class
'If the source item is an email or appointment
Case olMail, olAppointment
'Find the distribution list to update
Set olkLst = Session.GetDefaultFolder(olFolderContacts).Items.Find("[Name] = '" & LIST_NAME & "'")
If TypeName(olkLst) = "Nothing" Then
MsgBox "I could not find a distribution list named '" & LIST_NAME & "'.", vbCritical + vbOKOnly, "Operation Cancelled "
Else
With olkLst
'If the source item is an email, then add the sender
If olkItm.Class = olMail Then
Set olkRcp = Session.CreateRecipient(olkItm.SenderEmailAddress)
olkRcp.Resolve
.AddMember olkRcp
End If
'Loop through the recipients of the source item
For Each olkRcp In olkItm.Recipients
'If the recipient is not the current user
If olkRcp.Name <> Session.CurrentUser.Name Then
'If the source item an email or if it is an appointment and the recipient is not a resource
If (olkItm.Class = olMail) Or (olkItm.Class = olAppointment And olkRcp.Type <> olResource) Then
'Add the recipient to the list
.AddMember olkRcp
End If
End If
DoEvents
Next
.Display
End With
End If
End Select
End If
Set olkItm = Nothing
Set olkRcp = Nothing
Set olkLst = Nothing
End Sub