2015-03-31 97 views
1

我試圖創建一個宏,它將從我的Excel工作表中填入一列電子郵件地址並填充Outlook電子郵件中的「收件人」字段。我有基本的工作,我能夠創建一個新的Outlook電子郵件與我指定的各種字段值 - 但是,我不知道如何填充多個電子郵件地址到「收件人」字段,一個電子郵件。Excel VBA字符串數組到Outlook電子郵件「收件人」字段

截至目前,我能夠創建一個包含所有所需電子郵件地址的數組,但無法弄清楚如何將數組值填充到Outlook「To」字段中。

+0

顯示你當前的代碼 – 2015-03-31 16:25:50

回答

1

這是基於尤金的答案,編輯成包括Excel中實現

Sub CreateStatusReportToBoss(addRng as Excel.Range) 
    Dim myItem As Outlook.MailItem 
    Dim myRecipient As Outlook.Recipient 
    Set myItem = Application.CreateItem(olMailItem) 
    For Each cell in addRng 
    Set myRecipient = myItem.Recipients.Add(cell.Value) 
    Next cell 
    myItem.Subject = "Status Report" 
    myItem.Display 
End Sub 
+0

我已經添加了Microsoft Outlook 15引用,然後我也收到錯誤「對象不支持類型或方法」在第3行(CreateItem)中。 – User5590 2015-07-21 04:37:55

1

這可能有幫助,但概念與項目有點不同。希望這有助於過去用於類似案例但過程,只會提供maproad。

Sub CreateMail() 

Dim objOutlook As Object 
Dim objMail As Object 
Dim rngTo As Range 
Dim rngCc As Range 
Dim rngSubject As Range 
Dim rngBody As Range 

Set objOutlook = CreateObject("Outlook.Application") 
Set objMail = objOutlook.CreateItem(0) 

With ActiveSheet 
    Set rngTo = .Range("B1") 
    Set rngCc = .Range("B2") 
    Set rngSubject = .Range("B3") 
    Set rngBody = .Range(.Range("B4"), .Range("B4").End(xlDown)) 
End With 
rngBody.Copy 

With objMail 
    .To = rngTo.Value 
    .Cc = rngCc.Value 
    .Subject = rngSubject.Value 
    .Display 
End With 
SendKeys "^({v})", True 

Set objOutlook = Nothing 
Set objMail = Nothing 
Set rngTo = Nothing 
Set rngCc = Nothing 
Set rngSubject = Nothing 
Set rngBody = Nothing 

End Sub 
+0

謝謝大家。我能夠完成我正在嘗試使用我在此處找到的「字符串濃縮」功能:http://www.cpearson.com/excel/stringconcatenation.aspx 但是,您的解決方案非常直截了當。謝謝! – user1130306 2015-03-31 16:43:50

1

您可以使用MailItem類的Recipients屬性添加多個收件人。它還允許指定收件人的類型:收件人,抄送或密件抄送。

Sub CreateStatusReportToBoss() 
    Dim myItem As Outlook.MailItem 
    Dim myRecipient As Outlook.Recipient 
    Set myItem = Application.CreateItem(olMailItem) 
    Set myRecipient = myItem.Recipients.Add("Dan Wilson") 
    myItem.Subject = "Status Report" 
    myItem.Display 
End Sub 
相關問題