将Excel值输出格式化为Outlook

我正在尝试创build一个从Excel抓取信息并将其输出到Outlook的工具。

到目前为止这么好,但我无法得到一个数值显示在电子邮件格式。 它显示为简单的数字,例如203486442 ,但我想它是$203,486,441.93而不是。 尝试格式化时出现“无效限定符”错误。 这个数字是从我的工作表中的“总计”表中拉出的。

 Sub Test1() Application.ScreenUpdating = False Application.DisplayAlerts = False Dim OutApp As Object Dim OutMail As Object Dim cell As Range Set OutApp = CreateObject("Outlook.Application") Dim LastRow As Long Dim LastValue As Long LastRow = Sheets("Detail Aging").Range("E" & Rows.Count).End(xlUp).Row LastValue = Sheets("Detail Aging").Range("E" & LastRow).Value Dim strbody As String For Each cell In Worksheets("Body").Range("B2:B6") strbody = strbody & cell.Value & vbNewLine Next On Error GoTo cleanup For Each cell In Columns("D").Cells.SpecialCells(xlCellTypeConstants) If cell.Value Like "?*@?*.?*" And _ LCase(Cells(cell.Row, "E").Value) = "yes" Then Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = cell.Value .CC = Cells(cell.Row, "G").Value .Subject = "CompuCom Reminder Letter | " & Cells(cell.Row, "B").Value .Body = "Dear " & Cells(cell.Row, "C").Value & "," _ & vbNewLine & vbNewLine & _ "This is a friendly reminder that the " & _ "total balance due amount on your account is " & LastValue _ & vbNewLine & vbNewLine & _ "Here is the list of outstanding transactions:" _ & vbNewLine & vbNewLine & _ "Please let us know what the payment status is and if you require additional " & _ "information or documentation to process the invoice(s) for payment." _ & vbNewLine & vbNewLine & _ "Thank you." _ & vbNewLine & vbNewLine & _ Cells(cell.Row, "F").Value & vbNewLine & _ Cells(cell.Row, "G").Value & vbNewLine & _ Cells(cell.Row, "H").Value & vbNewLine & _ "Regards," .Display End With On Error GoTo 0 Set OutMail = Nothing End If Next cell 

尝试使用单元格的.Text属性而不是.Value

您将需要更改您的Lastvalue声明,请尝试:

 Dim lastValue As String ' or As Variant