我有以下宏。它需要从打开的 Outlook 电子邮件的主题行中提取一个 5 位数字。主题行的一个示例是“谢谢。订单:#98512”(不带引号)。

我确实在正则表达式 5.5 的 Outlook 引用中检查了该库。

我没有得到任何输出。只有以下错误。

The bug highlighter throws and error:
Run-Time error '450':
Wrong Number of arguments or invalid property assignment
With highlights on the MsgBox orderNumber command.

这是当前的宏:
Sub ShowTitle()
        Dim orderNumber
        Dim orderRegExp
        Dim regExVar As String
        Dim CurrentMessage As MailItem

    'Takes the email title from the subject line
        Set CurrentMessage = ActiveInspector.CurrentItem
        regExVar = CurrentMessage.Subject

    'Regex out the order number from the regExVar

        Set orderRegExp = New RegExp
        orderRegExp.Pattern = " \d{5} "
        orderRegExp.Pattern = True
        Set orderNumber = orderRegExp.Execute(regExVar)


    'displays in a message box
        MsgBox orderNumber

End Sub

最佳答案

希望这会做你需要的。

Sub ShowTitle()
    Dim orderNumber
    Dim orderRegExp As RegExp
    Dim regExVar As String

    ' Takes the email title from the subject line
    regExVar = "Thank you. Order:#98512"

    Set orderRegExp = New RegExp
    ' \s    Match any space character
    ' \S    Match any non-space character
    ' \d    Match any digit
    ' [xyz] Match any one character enclosed in the character set
    ' {}    Specifies how many times a token can be repeated
    ' $     Match must occur at the end of the string

    orderRegExp.Pattern = "[\s\S]\d{4}$"

    If orderRegExp.test(regExVar) Then
        Set orderNumber = orderRegExp.Execute(regExVar)
        'displays in a message box
        MsgBox orderNumber(0).value
    End If
End Sub

关于正则表达式 来自 MS Outlook 主题行的 5 位数字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27713715/

10-14 05:36