在Excel-VBA中编写的电子邮件中的十进制分隔符(HTML / CSS)
我有以下简单的Excel电子表格:
ABC 1 25,000,000.50 2 3
和下面的VBA代码发送电子邮件与内容的单元格A1 :
Sub Separators_in_Email() If ExitAll = False Then Dim OApp As Object, OMail As Object, signature As String Set OApp = CreateObject("Outlook.Application") Set OMail = OApp.CreateItem(0) With OMail .display End With signature = OMail.HTMLBody With OMail .To = "test@test.de" .Subject = "test" .HTMLBody = "<p> I want this number " & Sheet1.Range("A1") & " to be shown with its decimal separators as in the Excel sheet</p>" End With Set OMail = Nothing Set OApp = Nothing Else End If End Sub
电子邮件本身的作品完美。
但是,正如您在Excel电子表格中所看到的,我使用“,”作为小数点分隔符。 在电子邮件中,不使用这个小数点分隔符。 这个数字写成25000000.5,没有“,”。
有没有在VBA或HTML / CSS的方式来显示正确的小数点分隔符表中的数字?
用你的代码行:
.HTMLBody = "<p> I want this number " & Sheet1.Range("A1") & " to be shown with its decimal separators as in the Excel sheet</p>"
您应该用Sheet1.Range("A1")
replaceSheet1.Range("A1").Text
将返回单元格的格式化值。
当您使用Sheet1.Range("A1")
它将返回单元格的默认属性 – Value
– 其中包含一个未格式化的值。 看到这里
CSS / HTML不是这个问题的一个因素。