【发布时间】:2018-07-20 10:36:15
【问题描述】:
我编译了这个由规则触发的脚本,以在电子邮件 (DCSXXXX) 中查找参考号(在 Outlook 中使用 VBA)并将此电子邮件保存在同名文件夹。
但是,如果文件夹名称为 "DCSXXX [any text]",我试图找到一种让脚本工作的方法,这意味着我只有文件夹的开头使用的名称。有什么想法吗?
Public Sub GetValueUsingRegEx(myItem As MailItem)
' Set reference to VB Script library
' Microsoft VBScript Regular Expressions 5.5
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim colMatches As matchCollection
Dim M1 As Match
Dim Path As String
Dim enviro As String
Dim Match As String
Path = "X:\Path"
Set olMail = myItem
Set Reg1 = New RegExp
Reg1.IgnoreCase = True
Reg1.Pattern = "DCS\d\d\d\d\d?"
Reg1.Global = False
If Reg1.test(olMail.Body) Then
Set colMatches = Reg1.Execute(olMail.Body)
Match = Reg1.Execute(olMail.Body)(0)
For Each M1 In colMatches
MsgBox (M1)
Next
End If
Subject = olMail.Subject
Subject = Replace(Subject, ":", "_")
fullPath = (Path & "" & Match & "" & Subject & ".msg")
olMail.SaveAs (fullPath)
MsgBox fullPath
MsgBox Match
MsgBox Subject
MsgBox ("Done")
End Sub
【问题讨论】:
-
总是
DCS + 4 digits? -
或者五位数,这就是为什么我认为 Reg1.Pattern = "DCS\d\d\d\d\d?"会成功的