【发布时间】:2021-04-27 23:55:47
【问题描述】:
我已经为这个问题苦苦挣扎了一段时间,如果能提供任何帮助,我将不胜感激。所以我有从我拥有的 excel 文件生成电子邮件的代码。问题是当电子邮件粘贴在表格上时格式不正确。我附上了输出的截图,代码如下。
Sub Send_Email()
'Updated by Extendoffice 20200119
Dim xRg As Range
Dim I, J As Long
Dim xAddress As String
Dim xEmailBody As String
Dim xMailOut As Outlook.MailItem
Dim xOutApp As Outlook.Application
On Error Resume Next
xAddress = ActiveWindow.RangeSelection.Address
Set xRg = Range("A9:E32")
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Set xOutApp = CreateObject("Outlook.Application")
Set xMailOut = xOutApp.CreateItem(olMailItem)
For I = 1 To xRg.Rows.Count
For J = 1 To xRg.Columns.Count
xEmailBody = xEmailBody & " " & xRg.Cells(I, J).Value
Next
xEmailBody = xEmailBody & vbNewLine
Next
xEmailBody = "" & vbLf & vbLf & "" & vbLf & vbLf & xEmailBody & vbNewLine
With xMailOut
.Subject = Worksheets("TDN Generator").Range("A6").Value
.To = ""
.Body = xEmailBody
.Display
'.Send
End With
Set xMailOut = Nothing
Set xOutApp = Nothing
Application.ScreenUpdating = True
End Sub
这就是它粘贴到电子邮件中的方式:
Hello,
Check it out:
Trade 2
Trade Type Grant Number Security Type Shares Sold Shares Exercised
Sell To Cover 12345 Restricted Stock 200
Sell To Cover 12346 Restricted Stock 220
Sell To Cover 12347 Restricted Stock 240
Sell To Cover 12348 Restricted Stock 260
Sell To Cover 12349 Restricted Stock 280
我希望他们都在他们所说的列中正确对齐。
【问题讨论】: