Alfie Panelo
Member
- Outlook version
- Outlook 2010 64 bit
- Email Account
- Exchange Server
Hello All,
I'm having trouble coding Regex with vba
Can anyone help me with missing part to make the Outlook VBA script below work?
What I'm trying to do is filter the email body that contains a less than symbol <, it will forward to a specific email address.
Here is so far what I have.
Public Sub FWItem(Item As Outlook.mailitem)
Dim Email As Outlook.mailitem
Dim Matches As Variant
Dim RegExp As Object
Dim Pattern As String
Set RegExp = CreateObject("VbScript.RegExp")
If TypeOf Item Is Outlook.mailitem Then
Pattern = "(\s[<]\s)"
With RegExp
.Global = False
.Pattern = Pattern
.IgnoreCase = True
Set Matches = .Execute(Item.Body)
End With
If Matches.Count > 0 Then
Debug.Print Item.subject ' Print on Immediate Window
Set Email = Item.Forward
Email.subject = Item.subject
Email.Recipients.Add "alias@domain.com"
Email.Save
Email.Send
End If
End If
Set RegExp = Nothing
Set Matches = Nothing
Set Email = Nothing
Set Item = Nothing
End Sub
Here is a sample email text:
"That was fast! It only took < 60 seconds to reboot the modem."
If there is a space between < and 60, it will forwarded to my email but if there are no space, it won't.
Thank you,
I'm having trouble coding Regex with vba
Can anyone help me with missing part to make the Outlook VBA script below work?
What I'm trying to do is filter the email body that contains a less than symbol <, it will forward to a specific email address.
Here is so far what I have.
Public Sub FWItem(Item As Outlook.mailitem)
Dim Email As Outlook.mailitem
Dim Matches As Variant
Dim RegExp As Object
Dim Pattern As String
Set RegExp = CreateObject("VbScript.RegExp")
If TypeOf Item Is Outlook.mailitem Then
Pattern = "(\s[<]\s)"
With RegExp
.Global = False
.Pattern = Pattern
.IgnoreCase = True
Set Matches = .Execute(Item.Body)
End With
If Matches.Count > 0 Then
Debug.Print Item.subject ' Print on Immediate Window
Set Email = Item.Forward
Email.subject = Item.subject
Email.Recipients.Add "alias@domain.com"
Email.Save
Email.Send
End If
End If
Set RegExp = Nothing
Set Matches = Nothing
Set Email = Nothing
Set Item = Nothing
End Sub
Here is a sample email text:
"That was fast! It only took < 60 seconds to reboot the modem."
If there is a space between < and 60, it will forwarded to my email but if there are no space, it won't.
Thank you,