通过 Excel VBA 通过 outlook 发送电子邮件 - 将字符串转换为货币格式或百分比

Send E-mail through outlook via Excel VBA - convert string to currency format or percent

网站新手,programming/VBA 非常新。

我在一家销售公司工作,我想向我们的每个销售代表发送一封基本电子邮件,让他们知道他们的月销售额与目标以及目标的百分比

这是我的(非常基本的)代码 我需要将 'May_Sales' 和 'May_Goal' 格式化为货币,将 'May_Percent' 格式化为带 2 位小数的百分比 (16.14%)

' SendMassEmail Macro
'
row_number = 1

Do
DoEvents
    row_number = row_number + 1
    Dim mail_body_message As String
    Dim full_name As String
    Dim May_Sales As String
    Dim May_Goal As String
    Dim May_Percent As String

mail_body_message = "Good morning replace_name_here!" & vbNewLine & "Your Total Sales for May 2015 are May_Sales_replace" & vbNewLine & "Your Total Goal for May 2015 is May_Goal_replace" & vbNewLine & "You are currently at May_Percent_replace of your May Goal" & vbNewLine & "Thanks," & vbNewLine & "John Angerami"
full_name = Sheet1.Range("B" & row_number)
May_Sales = Sheet1.Range("C" & row_number)
May_Goal = Sheet1.Range("D" & row_number)
May_Percent = Sheet1.Range("E" & row_number)

mail_body_message = Replace(mail_body_message, "replace_name_here", full_name)
mail_body_message = Replace(mail_body_message, "May_Sales_replace", May_Sales)
mail_body_message = Replace(mail_body_message, "May_Goal_replace", May_Goal)
mail_body_message = Replace(mail_body_message, "May_Percent_replace", May_Percent)

Call SendEmail(Sheet1.Range("A" & row_number), "Daily Sales " & Sheet1.Range("F1"), mail_body_message)


Loop Until row_number = 2

'End Sub

您将在 VBA 中使用 Format 函数。

示例:

Format(May_Sales,"Currency")
Format(May_Percent,"0.00%")