6
我正在構建一個Excel加載項,它將活動工作簿作爲Outlook電子郵件模板中的附件發送到特定聯繫人組。如何訪問Excel VBA中的聯繫人組?
我已經得到了前兩個部分,使用下面的代碼,但我不知道如何將.TO
字段設置爲聯繫人組。
Public Sub Mail_Reports()
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
On Error Resume Next
Set OutApp = CreateObject("Outlook.Application")
'Set this line to the path and file name of your template
Set OutMail = OutApp.CreateItemFromTemplate("C:\Users\moses\AppData\Roaming\Microsoft\Templates\test.oft")
On Error Resume Next
With OutMail
'.TO field should be set to the contact group
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.HTMLBody = Replace(OutMail.HTMLBody, strOldPeriod, strNewPeriod)
.Subject = Replace(OutMail.Subject, strOldPeriod, strNewPeriod)
'To display the email leave as is; to send the Email, change to .Send
.Display 'or Send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
無視它,它確實有效。我的困惑是,儘管它作爲一個純文本值填充該字段,但Outlook足夠聰明,可以將其識別爲聯繫人組。我一直都有答案,但是不知道XD。 – Moses 2012-04-06 22:08:31
我也注意到它似乎沒有解決,應該在我的答案中提到它。如果您點擊「支票姓名」,就會發現,即使您沒有發送,也可以發送。 – 2012-04-06 22:18:23
嘿,老,我知道,但是那個鏈接被打破了 - 你能否把Ron的答案的相關片段放在這裏 - 假設你還有它? – Huw 2016-12-06 14:15:57