如何基于行值在Outlook中自动发送电子邮件

时间:2019-07-17 01:06:24

标签: excel vba outlook

您好,我有VBA Excel代码,它将基于excel值自动通过电子邮件将Outlook中的数据发送给Outlook,但仅在列有所有电子邮件的A列中发送为例

EMAIL                   TAG NUMBER        DESCRIPTION
angelobac@gmail.com      12334              code
iwant34@gmail.com        33333              vba

是否有可能基于电子邮件输入以及excel中的相同格式发送数据?

Sub emailthis()


Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object

Set outlook = CreateObject("Outlook.Application")
Set newEmail = outlook.CreateItem(0)

With newEmail
    .To = Sheet1.Range("A2").Text
    .CC = ""
    .BCC = ""
    .Subject = "Data"
    .Body = "Please find the requested information" & vbCrLf & "Best Regards"
    .display

    Set xInspect = newEmail.GetInspector
    Set pageEditor = xInspect.WordEditor

    Sheet1.Range("B2:I5").Copy

    pageEditor.Application.Selection.Start = Len(.Body)
    pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
    pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
    .display
    .Send
    Set pageEditor = Nothing
    Set xInspect = Nothing
End With

Set newEmail = Nothing
Set outlook = Nothing

End Sub

0 个答案:

没有答案