在 Outlook 中使用 InputBox 时如何确保获得货币值?

How can I ensure I get a currency value when using an InputBox in Outlook?

我正在尝试从作为货币的 InputBox 中获取一个值(每三位逗号和两位小数。

当我将 12345.60 放入 InputBox 时,我得到 12345.6 。我原本希望得到 12,345.60

下面是我的代码的精简版。

Public Sub MoneyTest()
Dim MoneyInput       As Currency

MoneyInput = InputBox("What is the Money Input ?")

Set objMsg = Application.CreateItem(olMailItem)
Set objFSO = CreateObject("Scripting.FileSystemObject")

With objMsg

.HTMLBody = MoneyInput

.Display
End With
End Sub

InputBox函数在对话框中显示提示,等待用户输入文本或单击按钮,returns包含文本框内容的字符串。

Public Sub MoneyTest()
Dim MoneyInput As String

MoneyInput = InputBox("What is the Money Input ?")

Set objMsg = Application.CreateItem(olMailItem)
Set objFSO = CreateObject("Scripting.FileSystemObject")

With objMsg

.HTMLBody = "<html><body>" & MoneyInput & "</body></html>"

.Display

End With
End Sub

另一个方面是,在将其分配给 HTMLBody 属性 之前,您应该创建一个格式正确的 HTML 标记字符串以避免任何格式设置。

InpoutBox returns 一个字符串,如何格式化该字符串由您决定。你可以尝试使用FormatCurrency函数