如何在复制的Excel表格之间向电子邮件添加文本?

如何在复制的Excel表格之间向电子邮件添加文本?,excel,vba,outlook,Excel,Vba,Outlook,我试图在从Excel获取数据时生成Outlook电子邮件 在复制的Excel表格之间放置文本时遇到问题 这是我想要的电子邮件结构 团队, 请参阅以下报告 技术-30 业务-30 技术报告: 这里是Excel格式的表格 运营报告: 这里是Excel格式的表格 这是我的密码: Sub Generate_Email() Dim outlook As Object Dim newEmail As Object Dim xInspect As Object Dim pageEditor As Objec

我试图在从Excel获取数据时生成Outlook电子邮件

在复制的Excel表格之间放置文本时遇到问题

这是我想要的电子邮件结构

团队,
请参阅以下报告

技术-30
业务-30

技术报告:

这里是Excel格式的表格

运营报告:

这里是Excel格式的表格

<此处的电子邮件签名>

这是我的密码:

Sub Generate_Email()
Dim outlook As Object
Dim newEmail As Object
Dim xInspect As Object
Dim pageEditor As Object
Dim headerMessage As String
Dim operationalHeader As String
Dim technicalHeader As String

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

' Get count of Operational SS
opCount = ActiveWorkbook.Worksheets("Operationals").Range("A2", Worksheets("Operationals").Range("A2").End(xlDown)).Rows.Count

 ' Get count of Technicals SS
techCount = ActiveWorkbook.Worksheets("Technicals").Range("A2", Worksheets("Technicals").Range("A2").End(xlDown)).Rows.Count

headerMessage = "Team," & vbCrLf & vbCrLf & "Please see each list below for stores with three or more days of technical and/or operational showstoppers." _
& vbCrLf & vbCrLf & "Total Showstoppers:" & vbCrLf & "Technical - " & techCount & vbCrLf & "Operational - " & opCount & vbCrLf & vbCrLf & "Technical Showstopper List:" & vbCrLf

headerLength = Len(headerMessage) - 11

With newEmail
    .To = "email@shomewhere.com"
    .CC = ""
    .BCC = ""
    .Subject = "Showstopper Report " & Date


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

    ' ADD TECHNICAL SHOWSTOPPER REPORT TABLE
    pageEditor.Range.InsertBefore headerMessage
    Sheet4.Range("A1").CurrentRegion.Copy
    pageEditor.Range(headerLength).Paste


    ' ADD OPERATIONAL SHOWSTOPPER REPORT Table
    pageEditor.Range.InsertAfter vbCrLf & "Operational Showstopper List:" & vbCrLf
    Sheet3.Range("A1").CurrentRegion.Copy
    pageEditor.Application.Selection.Paste

    'pageEditor.Application.Selection.End = pageEditor.Application.Selection.End
    'pageEditor.Application.Selection.End = pageEditor.Application.Selection.EndKey
    pageEditor.Application.Selection.Paste


    .Display

    'Set pageEditor = Nothing
    'Set xInspect = Nothing

End With

Set newEmail = Nothing
Set outlook = Nothing

End Sub

就我个人而言,我只需要在电子邮件中创建一个包含所有内容的长字符串,然后说newEmail.Body=mystring为什么不将范围更改为HTML并将其放在outlook中。请找到Ron de Bruin的这篇文章,看看它是如何工作的。希望将帮助您解决问题:)当我将excel表构建为一个长字符串时,如何包含它?