
我有一個 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 時可以保留表格和格式嗎?如果是,怎麼辦?