修改 VBA 代码以在复制到 Outlook 之前保留 Excel 表上的数据格式

修改 VBA 代码以在复制到 Outlook 之前保留 Excel 表上的数据格式

我有一个 VBA,可以将详细信息从 Excel 表复制到 Outlook 邮件正文:下面是宏:

Sub Send_Email()

Dim EmailSubject As String
Dim SendTo As String
Dim EmailBody As String
Dim ccTo As String

EmailSubject = "Test"
SendTo = "[email protected]"


FirstRow = 1 
LastRow = 5
FirstCol = 1 
LastCol = 2 

For r = FirstRow To LastRow
For c = FirstCol To LastCol

For Each cell In Cells(r, c)
strtable = strtable & "  " & cell.Value
Next
Next
strtable = strtable & vbNewLine
Next

EmailBody = "Hi" & vbLf & vbLf & " body" & vbLf & vbLf & strtable & vbNewLine 

Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = EmailSubject
.To = SendTo
.CC = ccTo
.Body = EmailBody
.Display
'.Send
End With
Set App = Nothing
Set Itm = Nothing
End Sub

但是 Excel 表上的详细信息是表格格式,带有一些格式。将数据复制到 Outlook 中时,表格和格式可以保留吗?如果可以,如何保留?

相关内容