【问题标题】:Word VBA, Finding price and giving a alertWord VBA,查找价格并发出警报
【发布时间】:2021-06-16 16:55:32
【问题描述】:

我目前正在编写一个宏来查找订单的总价。所以我实际上希望宏在 Word 文档中找到“Totaal”(总计)并选择下一个单词,订单的总价格是多少。

例如,总计 € 9.900,78 选择 9.900,78

With ActiveDocument.Range
    With Selection.Find
        .ClearFormatting
        .MatchWholeWord = True
        .MatchCase = False
        .Execute FindText:="Totaal"
        Selection.MoveRight Unit:=wdWord, Count:=2
        With Selection
            .MoveEndUntil Cset:=",", Count:=wdForward
            .MoveRight Unit:=wdCharacter, Count:=0, Extend:=wdExtend
        End With
    End With
    Do While .Find.Found
        .Collapse wdCollapseEnd
        .Find.Execute
    Loop
End With

然后,如果它被选中,如果选择/价格高于某个价格,它应该制作一个 msgbox。但我实际上不知道如何实现该功能。我真的希望你们能帮助我。

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    例如:

    Sub Test()
    Dim Amt As Single
    With ActiveDocument.Range
      With .Find
        .ClearFormatting
        .MatchWildcards = True
        .Text = "Totaal €?@[0-9,.]{1,}"
        .Execute
        End With
        Do While .Find.Found
          Amt = CSng(Trim(Split(.Text, "€")(1)))
          If Amt > 1000 Then MsgBox Amt
          .Collapse wdCollapseEnd
          .Find.Execute
        Loop
    End With
    End Sub
    

    【讨论】:

      【解决方案2】:

      非常感谢,现在可以使用了

      Dim Amt As Single
      Dim gedaan As Variant
      With ActiveDocument.Range
        With .Find
          .ClearFormatting
          .MatchWildcards = True
          .Text = "Totaal?€?@[0-9;.]{1;}"
          .Execute
          End With
          Do While .Find.Found
            Amt = CSng(Trim(Split(.Text, "€")(1)))
            If Amt > 15000 Then MsgBox "Je moet 10/80/10 factuur maken!!"
            .Collapse wdCollapseEnd
            .Find.Execute
          gedaan = InputBox("Schrijf hier iets als je dat heb gedaan", "Gedaan", "")
          If StrPtr(gedaan) = 0 Then
              MsgBox ("Orderbevestiging word afgesloten!")
              Exit Sub
          ElseIf gedaan = vbNullString Then
              MsgBox ("Orderbevestiging word afgesloten!")
          Exit Sub
          Else
              MsgBox ("We gaan verder met de orderbevestiging ")
          End If
          Loop
      End With

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-03-24
        • 1970-01-01
        • 1970-01-01
        • 2013-11-09
        • 1970-01-01
        • 1970-01-01
        • 2012-03-08
        相关资源
        最近更新 更多