如何将TextBox内容作为电子邮件正文发送?

时间:2019-07-29 19:44:28

标签: excel vba email

我正在尝试通过按按钮发送电子邮件。除电子邮件正文外,其他所有内容均正常运行。它始终显示为空白。该正文被键入到TextBox1(非用户窗体)中。我希望将其放在文本框中将在发送电子邮件时对其进行格式化。

Sub Email()

    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim ChartName As String

    Set OutApp = CreateObject("Outlook.Application")
    ChartName = Environ$("temp") & "\Chart4.gif"
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next

    ActiveWorkbook.Worksheets("Send Email").ChartObjects("Chart 4").Chart.Export _
        Filename:=ChartName, FilterName:="GIF"

    With OutMail
        .To = Range("A2")
        .CC = ""
        .BCC = ""
        .Subject = Range("A4")

        '.body is the only thing not working it always shows up blank
        .Body = Worksheets("Send Email").TextBox1.Value
        .Attachments.Add ChartName
        .Display 'will use send when working

    End With
    On Error GoTo 0
    Kill ChartName
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub

0 个答案:

没有答案