有一點問題,我希望有人能幫助我。Outlook 2010 VBA - 添加發件人到聯繫人當我點擊一個郵件
(如Outlook 2010 VBA)
這是我當前的代碼,我需要的是當我在郵件上的(只有郵件我點擊,而不是在文件夾/同一個地方每封郵件)點擊 有要檢查郵件的發送者已經在我的聯繫人或 通訊錄「所有用戶」, ,如果它不是其中一個呢,打開的addContact窗口,並在他/她的信息填寫
什麼不起作用的是:
- 最重要的是,當我點擊郵件時它不運行腳本
- 當前檢查聯繫人是否已經存在不起作用 並且帶有vbMsgBox(是或否和響應的東西)不是我想要的/需要的 如果聯繫人已經存在,則不需要發生任何事情。
我希望我給了足夠的信息,並有人能幫助我在這裏:)
Sub AddAddressesToContacts(objMail As Outlook.MailItem)
Dim folContacts As Outlook.MAPIFolder
Dim colItems As Outlook.Items
Dim oContact As Outlook.ContactItem
Dim oMail As Outlook.MailItem
Dim obj As Object
Dim oNS As Outlook.NameSpace
''don't want or need a vbBox/ask box, this is a part of the current contactcheck
''wich doesn't work and is totaly wrong :P
Dim response As VbMsgBoxResult
Dim bContinue As Boolean
Dim sSenderName As String
On Error Resume Next
Set oNS = Application.GetNamespace("MAPI")
Set folContacts = oNS.GetDefaultFolder(olFolderContacts)
Set colItems = folContacts.Items
''this selects the mail that is currently selected.
''what i want is that the sender of the new incoming mail gets added to contacts
''(ofcourse, if that contact doesn't exsist yet)
''so the new incoming mail gotta be selected.
For Each obj In Application.ActiveExplorer.Selection
If obj.Class = olMail Then
Set oContact = Nothing
bContinue = True
sSenderName = ""
Set oMail = obj
sSenderName = oMail.SentOnBehalfOfName
If sSenderName = ";" Then
sSenderName = oMail.SenderName
End If
Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")
''this part till the --- is wrong, i need someting to check if the contact (the sender)
''already exsists. Any ideas?
If Not (oContact Is Nothing) Then
response = vbAbort
If response = vbAbort Then
bContinue = False
End If
End If
''---------
If bContinue Then
Set oContact = colItems.Add(olContactItem)
With oContact
.Email1Address = oMail.SenderEmailAddress
.Email1DisplayName = sSenderName
.Email1AddressType = oMail.SenderEmailType
.FullName = oMail.SenderName
'.Save
oContact.Display
End With
End If
End If
Next
Set folContacts = Nothing
Set colItems = Nothing
Set oContact = Nothing
Set oMail = Nothing
Set obj = Nothing
Set oNS = Nothing
End Sub
哎,我還是有最後一個問題,
'sets the name of the contact
Set oContact = colItems.Find("[FullName] = '" & sSenderName & "'")
'checks if the contact exsist, if it does exit the for loop
If Not oContact Is Nothing Then
Exit For
End If
End If
此檢查,如果名稱是已經在聯繫人, 我需要它,它會檢查電子郵件是否在聯繫人或不, 你能幫我嗎?
我有成才喜歡這一點
set oSendermail = ?the e-mailaddress?
If Not oSendermail Is Nothing Then
Exit For
End If
End If
定義發件人是否包含在你的地址簿中其中將所有傳入郵件到您的郵箱規則,然後停止規則處理。然後,只有發件人不在您的地址簿中才會調用第二條規則。第二條規則應該調用一個VBA子例程,它在將郵件移動到收件箱之前自動將發件人添加到地址簿中。如何定義規則在這裏解釋:http://superuser.com/questions/174145/can-you-create-a-rule-in-outlook-to-move-all-emails-that-were-sent-to -any-distri – 2013-02-26 10:30:19
嘿,感謝您的快速反應,這是我從我的老闆那裏得到的一個任務,而且這個任務必須貫穿整個公司,它必須檢查發件人是否存在,如果它沒有打開addContact窗口,如果你點擊一個郵件,而不是當你收到一封新郵件。我希望你能進一步幫助我:) – Ricje20 2013-02-26 10:32:40
好的。如果您的第一條規則具有發件人在地址簿中的前提條件,這意味着發件人存在。規則在用戶點擊郵件之前執行。你還有疑慮嗎? – 2013-02-26 10:40:53