I am trying to use Diane's solution but I am stuck.
I am trying to use your "Open a specific hyperlink" code. Can you let me know if the only thing I need to change is the .Pattern = "View this thread <(.*)>" part of the code? For example if I want to only click a link with the words "Claim Now" I would change my code to .Pattern = "Claim Now <(.*)>"?
As for the If InStr(strURL, "unsubscribe") Then GoTo NextURL section of the code, do I need to use this section to add all other links that I do not want to click on? I noticed that in the example there are 10 links but the author only seem to specify the "unsubscribe" link. For example, if I do not need to click on the link for contact information do I need to add something like If InStr(strURL, "contact-info") Then GoTo NextURL?
Here is what I have at the moment:
' 64bit office use:
'Private Declare PtrSafe Function ShellExecute _
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long
Sub OpenHyperLinkMessage(Item As Outlook.MailItem) *I had to add this to make is available when creating the rule*
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 = "Claim this Case Now <(.*)>" *This is the text of the link in the email*
.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
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If InStr(strURL, "referral-preference") Then GoTo NextURL *I do not know if I even need to add this or not to skip a specific link*
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
lSuccess = ShellExecute(0, "Open", strURL)
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub
Please advise.
Thank you.
I am trying to use your "Open a specific hyperlink" code. Can you let me know if the only thing I need to change is the .Pattern = "View this thread <(.*)>" part of the code? For example if I want to only click a link with the words "Claim Now" I would change my code to .Pattern = "Claim Now <(.*)>"?
As for the If InStr(strURL, "unsubscribe") Then GoTo NextURL section of the code, do I need to use this section to add all other links that I do not want to click on? I noticed that in the example there are 10 links but the author only seem to specify the "unsubscribe" link. For example, if I do not need to click on the link for contact information do I need to add something like If InStr(strURL, "contact-info") Then GoTo NextURL?
Here is what I have at the moment:
' 64bit office use:
'Private Declare PtrSafe Function ShellExecute _
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long
Sub OpenHyperLinkMessage(Item As Outlook.MailItem) *I had to add this to make is available when creating the rule*
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 = "Claim this Case Now <(.*)>" *This is the text of the link in the email*
.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
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If InStr(strURL, "referral-preference") Then GoTo NextURL *I do not know if I even need to add this or not to skip a specific link*
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
lSuccess = ShellExecute(0, "Open", strURL)
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub
Please advise.
Thank you.