我正在尝试将一系列单元格复制到已有一些文本的Outlook电子邮件的正文中。我目前的代码如下,但它一直崩溃:
Dim sourceWorkbook As Workbook
Dim outEmail As Object
Dim outContent As Object
Dim copiedRange As Range
Set sourceWorkbook = Workbook.Open("file location")
Set outEmail = GetObject(,"Outlook.Application")
Set outContent = objOut.CreateItem(0)
Set copiedRange = Sheet("sheet name").RangeToHtml("A1:D5")
copiedRange.Select
With Selection
.Copy
End With
With outContent
.Body = "blah blah blah"
.HTMLBody = RangeToHtml.copiedRange
End With
答案 0 :(得分:2)
Dim sourceWorkbook As Workbook
Dim outEmail As Object
Dim outContent As Object
Dim copiedRange As Range
Set sourceWorkbook = Workbooks.Open("file location")
Set outEmail = GetObject(,"Outlook.Application")
Set outContent = outEmail.CreateItem(0)
Set copiedRange = sourceWorkbook.Sheets("sheet name").Range("A1:D5")
With outContent
.Body = "blah blah blah"
.HTMLBody = RangeToHtml(copiedRange)
End With