I have a working macro (below): a certain type of email arrives and a rule directs it to a folder. I hand run a macro which extracts info from the body, creates a url, a launches in my default browser (Chrome). Does exactly as required.
I've converted to a script (below). The rule directs to the folder, and then runs the script. The extract and create step works, but not the launch.
I'm new to VBA programming so guess I've made a mistake/assumption somewhere?
Macro
====
Sub PostLog()
Dim MyMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strAddress As String
Dim objShell
Set MyMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
With Reg1
.Pattern = "my pattern"
.Global = False
End With
If Reg1.Test(MyMail.Body) Then
Set M1 = Reg1.Execute(MyMail.Body)
For Each M In M1
strAddress = "my url" + Mid(M, 19, 26)
Set objShell = CreateObject("Wscript.Shell")
objShell.Run (strAddress)
Next
End If
End Sub
Script
=====
Sub PostLog(MyMail As Outlook.MailItem)
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strAddress As String
Dim objShell
Set Reg1 = New RegExp
With Reg1
.Pattern = "my pattern"
.Global = False
End With
If Reg1.Test(MyMail.Body) Then
Set M1 = Reg1.Execute(MyMail.Body)
For Each M In M1
strAddress = "my url" + Mid(M, 19, 26)
Set objShell = CreateObject("Wscript.Shell")
objShell.Run (strAddress)
Next
End If
End Sub