我有以下简单的Excel电子表格:
A B C
1 25,000,000.50
2
3
以下VBA代码发送内容为 Cell 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中是否有一种方法可以使用正确的小数分隔符显示工作表中的数字?
答案 0 :(得分:1)
使用您的代码行:
.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")
替换为Sheet1.Range("A1").Text
,这将返回单元格的格式化值。
当您使用Sheet1.Range("A1")
时,它会返回单元格的默认属性 - Value
- 其中包含未格式化的值。见here
CSS / HTML不是解决此问题的因素。