我有1000多個聯繫人,每個聯繫人都有一組常用職位。我希望以編程方式將每個職位組(例如所有與職位名稱'總經理'的聯繫人)添加到分配名單(例如'總經理')中。將聯繫人添加到Outlook發佈清單
回答
好的,這裏只是默認聯繫人文件夾的一個例子。同樣,您必須前往DL可能存在的每個文件夾,從默認聯繫人文件夾開始,在創建Dist列表之前檢查它是否存在。
嘗試和測試(在Outlook VBA)
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
嗨。我得到一個錯誤91,對象變量或塊沒有設置在這一行:olRecipients.Add olAdLstEntry.GetContact.Email1Address - 我只有一個聯繫人和DList正確創建,並且聯繫人有一個email1地址。有任何想法嗎? – tonyyeb
我認爲它可能會找到剛創建並將其視爲聯繫人的DList。研究檢查聯繫人類型的方法,以及是否爲DList來跳過它。 – tonyyeb
好吧,我得到它的工作,但問題是聯繫人不添加到DList,只是他們的電子郵件地址。因此,當聯繫人更新爲新的電子郵件地址時,如果單擊「立即更新」,則此更改不會反映在DList中。 – tonyyeb
- 1. 添加聯繫人到Outlook
- 2. 添加Outlook聯繫人?在網站上
- 3. iOS - 將聯繫人添加到聯繫人?
- 4. 將聯繫人添加到聯繫人組
- 5. 如何將聯繫人添加到聯繫人表
- 6. 將聯繫人添加到特定組中? Google聯繫人API
- 7. 將大量聯繫人添加到iPhone聯繫人列表
- 8. 將聯繫人的事件添加到Android的聯繫人表
- 9. 使用聯繫人框架將聯繫人添加到組
- 10. Outlook 2010 VBA - 添加發件人到聯繫人當我點擊一個郵件
- 11. 將聯繫人添加到ListView
- 12. 將聯繫人添加到列表中
- 13. 將照片添加到聯繫人
- 14. 如何將聯繫人添加到com.android.provider.contacts?
- 15. 將聯繫人添加到ListView
- 16. 將照片添加到聯繫人
- 17. 將聯繫人添加到GlobalAddressList Exchange
- 18. 試圖將值添加到聯繫人
- 19. 將外部聯繫人添加到組
- 20. 將聯繫人添加到SIM卡
- 21. 微分Outlook聯繫人(聯繫人)
- 22. Outlook 2010簽名:添加到聯繫人鏈接
- 23. 常量聯繫C#Wrapper - 將聯繫人添加到列表
- 24. outlook addin發件人的聯繫方式
- 25. 使用Outlook聯繫人表單
- 26. 將按鈕或菜單項添加到選定的聯繫人
- 27. 將動畫添加到聯繫人表單
- 28. PHP:將聯繫人添加到列表mailjet V3簡單的API
- 29. 將工作複選框添加到聯繫人表單
- 30. 安卓:添加連接到聯繫人應用的聯繫人
很簡單。你有什麼嘗試? –
我正在從一本名爲「Outlook編程聖經」的書中嘗試一些例子,但沒有一個能夠完成我想要的,而且我沒有太多的運氣修改代碼。 – tonyyeb
你想要什麼代碼? –