如何更正为计算一个值乘另一个值而编写的代码

时间:2019-11-28 09:14:23

标签: vba

我正在尝试隐藏一张发票的值,以便该值乘以另一个金额以进行AMEX计算,如下所示,但由于计算出的答案为0,所以缺少某些内容。 有人可以协助吗?

Sub AMEX()
Dim Number_1 As Integer
Dim Number_2 As Integer
Dim Answer As Integer
Dim strBillAmt As Integer

Dim intNumLines As Integer

'Get the Bill amount from the doc
strBillAmt = GetValue("[BillAmt]")

Do
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "[AMEX]"
        .Replacement.Text = ""
        .Wrap = wdFindContinue
    End With
    If Selection.Find.Execute = True Then
        Selection.Delete Unit:=wdCharacter, Count:=1
            Number_1 = 1.0175
            Number_2 = strBillAmt
            Answer = Number_1 * Number_2

        Selection.InsertFormula Formula:="Answer"

     Else
        Exit Do
    End If
Loop

End Sub

1 个答案:

答案 0 :(得分:0)

我能够按以下方式进行操作:

Sub AMEX() Dim Number_1为整数,Number_2为整数 Dim Answer as Integer,strBillAmt As Integer 变暗的strAMEXAmt作为字符串

'从凭证中获取帐单金额 strBillAmt = GetValue(“ [BillAmt]”)

If Selection.Find.Execute("[AMEX]", Forward:=True, Wrap:=wdFindStop) Then
    AMEXAmt = strBillAmt * 1.0175
    Selection.TypeText Format(AMEXAmt, "$#,##0.00")
End If

结束子