2012-05-17 2 views
2

나는 공통된 직책을 각각 선택하여 1000 명이 넘는 연락처를 가지고 있습니다. 각 직책 그룹 (예 : 'Managing Director'직책을 가진 모든 연락처)을 배포 목록 (예 : 'Managing Director')에 프로그래밍 방식으로 추가하고 싶습니다.Outlook 배포 목록에 연락처 추가

+0

그것은 간단합니다. 너 뭐 해봤 니? –

+0

나는 Outlook Programming Bible이라고 불리는 책에서 몇 가지 예를 시도하고있다. 그러나 그들 중 누구도 내가 원하는 것을하지 않고 코드를 수정하는 것이별로 행운이 아니다. – tonyyeb

+0

어떤 코드를 사용하려고 했습니까? –

답변

6

다음은 기본 연락처 폴더의 예입니다. 마찬가지로 DL을 만들 수있는 폴더가 있는지 확인하기 위해 기본 연락처 폴더부터 시작하여 DL이있는 모든 폴더로 이동해야합니다. 시도 (전망 VBA IN) 테스트 완료

Option Explicit 

Sub GetJobList() 
    Dim olApp As Outlook.Application 
    Dim olNmspc As Outlook.NameSpace 
    Dim olAdLst As Outlook.AddressList 
    Dim olAdLstEntry As Outlook.AddressEntry 
    Dim olDLst As Outlook.DistListItem, olDLstItem As Outlook.DistListItem 
    Dim olMailItem As Outlook.MailItem 
    Dim olRecipients As Outlook.Recipients 

    Dim jobT() As String, JobTitle As String 
    Dim i As Long 

    Set olApp = New Outlook.Application 
    Set olNmspc = olApp.GetNamespace("MAPI") 

    i = 0 

    '~~> Loop through the address entries 
    For Each olAdLst In olNmspc.AddressLists 
     Select Case UCase(olAdLst.Name) 
      Case "CONTACTS" 
       '~~> Get the Job Title 
       For Each olAdLstEntry In olAdLst.AddressEntries 
        On Error Resume Next 
        JobTitle = Trim(olAdLstEntry.GetContact.JobTitle) 
        On Error GoTo 0 

        If JobTitle <> "" Then 
         ReDim Preserve jobT(i) 
         jobT(i) = olAdLstEntry.GetContact.JobTitle 
         i = i + 1 
        End If 
       Next 
     End Select 
    Next 

    '~~> Loop through the job title to create the distribution lists 
    For i = LBound(jobT) To UBound(jobT) 
     '~~> Check if the DL List exists 
     On Error Resume Next 
     Set olDLst = olNmspc.GetDefaultFolder(olFolderContacts).Items(jobT(i)) 
     On Error GoTo 0 

     '~~> If not then create it 
     If olDLst Is Nothing Then 
      Set olDLst = olApp.CreateItem(7) 
      olDLst.DLName = jobT(i) 
      olDLst.Save 
     End If 
    Next i 

    '~~> Loop through the address entries to add contact to relevant Distribution list 
    For Each olAdLst In olNmspc.AddressLists 
     Select Case UCase(olAdLst.Name) 
      Case "CONTACTS" 
       '~~> Get the Job Title 
       For Each olAdLstEntry In olAdLst.AddressEntries 
        On Error Resume Next 
        JobTitle = Trim(olAdLstEntry.GetContact.JobTitle) 
        On Error GoTo 0 

        If JobTitle <> "" Then 
         On Error Resume Next 
         Set olDLst = olNmspc.GetDefaultFolder(olFolderContacts).Items(JobTitle) 
         On Error GoTo 0 

         '~~> Create a mail item 
         Set olMailItem = olApp.CreateItem(0) 
         Set olRecipients = olMailItem.Recipients 
         olRecipients.Add olAdLstEntry.GetContact.Email1Address 

         '~~> Add to distribution list 
         With olDLst 
          .AddMembers olRecipients 
          .Close olSave 
         End With 

         Set olMailItem = Nothing 
         Set olRecipients = Nothing 
        End If 
       Next 
     End Select 
    Next 

    Set olNmspc = Nothing 
    Set olApp = Nothing 
    Set olDLst = Nothing 

End Sub 
+0

안녕하세요. olRecipients.Add olAdLstEntry.GetContact.Email1Address - 하나의 연락처 만 있고 DList가 올바르게 작성되었으며 연락처에 email1address가 있습니다. 어떤 아이디어? – tonyyeb

+0

방금 ​​생성 된 DList를 찾고 접촉으로 간주 할 수 있다고 생각합니다. 연락처 유형을 확인하는 방법을 살펴보고 건너 뛸 DList인지 확인합니다. – tonyyeb

+0

좋아, 나는 그것을 작동시키지 만, 문제는 연락처가 DList에 추가되지 않았으며, 단지 이메일 주소이다. 따라서 연락처가 새 이메일 주소로 업데이트되면 '지금 업데이트'를 클릭하면이 변경 사항이 DList에 반영되지 않습니다. – tonyyeb

관련 문제