aniaaneczka
New Member
- OS Version(s)
- Windows
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Operating system:: Windows 10
Outlook version: Outlook 2016
Email type or host: Microsoft 365
Outlook version: Outlook 2016
Email type or host: Microsoft 365
Hi,
I've tweaked my macro to open a link from an incoming email. It works very well from the Visual Basic window, but it doesn't work when applied within a rule in Outlook. Would anyone know what's wrong?
This is the script. It's in ThisOutlookSession.
Private Declare PtrSafe 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
Public Sub OpenLinksMessage()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strURL As String
Dim browserPath As String
browserPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
' opens the first link. use false to open all
.Global = False
.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)
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe" & " -url " & strURL)
DoEvents
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub
I've tweaked my macro to open a link from an incoming email. It works very well from the Visual Basic window, but it doesn't work when applied within a rule in Outlook. Would anyone know what's wrong?
This is the script. It's in ThisOutlookSession.
Private Declare PtrSafe 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
Public Sub OpenLinksMessage()
Dim olMail As Outlook.MailItem
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strURL As String
Dim browserPath As String
browserPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
Set olMail = Application.ActiveExplorer().Selection(1)
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
' opens the first link. use false to open all
.Global = False
.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)
If InStr(strURL, "unsubscribe") Then GoTo NextURL
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
Shell ("C:\Program Files\Google\Chrome\Application\chrome.exe" & " -url " & strURL)
DoEvents
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub