Sub OpenLinksMessage()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strURL As String
Dim lSuccess As Long
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
.Global = True
.IgnoreCase = True
End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
strURL = M.SubMatches(0)
Debug.Print strURL
' Either this block
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If InStr(strURL, "cads/images/") Then GoTo NextURL
If InStr(strURL, "http://www.choicehomewarranty.com/cads/decline.php*") Then GoTo NextURL
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
msgbox strurl ' during testing, to verify the link looks good
Debug.Print strURL
lSuccess = ShellExecute(0, "Open", strURL)
'end block
' or this block should work
If InStr(strURL, "http://www.choicehomewarranty.com/cads/accept.php") Then
msgbox strurl ' during testing, to verify the link looks good
Debug.Print strURL
lSuccess = ShellExecute(0, "Open", strURL)
exit sub ' if there is only one link yo open, exit sub once its found
end If
' end block
DoEvents
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub