Opening a link from a specific sender automatically

Post number 4 has been selected as the best answer.

Status
Not open for further replies.

aniaaneczka

Member
OS Version(s)
  1. Windows
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Operating system::    Windows 10
Outlook version:     classic Outlook
Email type or host:    Microsoft 365

Hi,

I need to have a link from a specific sender open automatically in Firefox when the email is received.
This is the macro I am testing. It is probably a mess.
I get a Compile error with "unexpected identifier" pointing to the line Sub OpenLinksMessage().

Can anyone tell me how to get the macro work?

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


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.Firefox().Selection(1)

Set Reg1 = New RegExp

With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
.Global = False
.IgnoreCase = True
End With

if item.senderemailaddress = "someone@something.com" 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 Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)

lSuccess = ShellExecute(0, "Open", strURL)
DoEvents

NextURL:
Next
End If

End if

Set Reg1 = Nothing
End Sub
 
Hi Diane, I use 64 bit windows and outlook. Unfortunately, it only works in the Visual Basic editor, but not in my Outlook, where I created a rule: when a message with a specific text in the title arrives, the script should be executed. This is the VB script I'm using:


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 = Chr(34) & "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & Chr(34)

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
 
That is not going to work in a rule -
Public Sub OpenLinksMessage()

needs to be something like Public Sub OpenLinksMessage(olMail as mailitem) - and the set olMail line removed.

these is an example here - there is one a bit under the first run a script macro for Run a script version for Chrome

Open Hyperlinks in an Outlook Email Message (slipstick.com)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
L Opening People Outlook 2021 Using Outlook 2
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
KurtLass Opening Graphics Attachments in Outlook 2021 Using Outlook 0
Witzker Place cursor at opening, a user defined OL contact form Outlook VBA and Custom Forms 2
A OutLook For Mac 16.46 Comes Up In Small Window When Opening Using Outlook 4
U Disable "Always ask before opening" Dialog Using Outlook 3
Wayne Outlook locks up when opening "Manage Rules & Alerts" Using Outlook 7
B Outlook 2010 Opening Mail Attachment Using Outlook 2
A Warning When Opening attachment Using Outlook 7
D Prevent popup of "Do you want to save changes?" when closing after opening an appointment to view Outlook VBA and Custom Forms 2
H Upon opening Outlook, make my popmail inbox open instead of outlook.com inbox Using Outlook 1
J Outlook 2010 Changing events in Outlook calendar via opening file, importing CSV Using Outlook 0
L What are the risks of opening an Outlook 2016 .pst file in Outlook 2010? Using Outlook 4
D Outlook 2007 crashes when opening an email Using Outlook 2
A Outlook 2016- unable to have all subfolders expanded when opening outlook Using Outlook 11
GregS Immediate crash on opening Using Outlook 3
Diane Poremsky Error Opening Outlook and Control Panel's Mail Applet Using Outlook 0
S my vbscript button1_click code works on appointment created but not on opening an existing apntmn Outlook VBA and Custom Forms 16
J Opening Attachments - in People Using Outlook 2
Mistyfied Outlook 2016 not opening Using Outlook 2
M Update field codes when opening Outlook Template Outlook VBA and Custom Forms 2
R Outlook PST not opening Using Outlook 1
U .pst file error at opening outlook Using Outlook 1
A Problems Opening Excel from Outlook Outlook VBA and Custom Forms 3
Diane Poremsky Disable the Unsafe Hyperlink Warning when Opening Attachments Using Outlook 0
S macro for opening attachments and printing Using Outlook 1
Z how to make OL (2007) to use custom contact form when importing / opening .VCF? Using Outlook 1
T Opening email causes "Contacting ..." message Using Outlook 1
K Outlook 2013 stuck "processing" when opening. Using Outlook 3
S Opening Outlook Windows Using Outlook 1
S PoP up reminder while opening the outlook? Outlook VBA and Custom Forms 1
J Opening/Archiving/Import/Export PST files Using Outlook 4
Y (Shared Folder) Using the preview pane to open and close a fax, without opening the email itself Using Outlook 1
E OL2007 on Exchange: opening OL on different computers Using Outlook 1
Z outlook 2007 - opening a contact from the search results doesn't use the custom form Using Outlook 10
T Error opening mail with pictures - "The linked image cannot be displayed" Using Outlook 3
P I'm getting an error when opening Outlook "Mobile me stopped working Using Outlook 1
D opening Word Document in a business contact? BCM (Business Contact Manager) 3
B Contact changes from Personal to Shared when opening custom form Using Outlook 0
C How to stop iCloud calendars opening by default Using Outlook 8
U outlook 2010 freezes/crashes when opening encrypted e-mails Using Outlook 0
G OLMAPI32.dII error prevents Outlook 2010 from opening Using Outlook 2
D Custom Tool Bar and/or Commands do not remain when re-opening Outlook 2007 Using Outlook 3
G opening Outlook again after closing closing? Using Outlook 0
B Outlook 2010: how to mark messages without opening? Eg for deletion Using Outlook 2
M I cannot start Microsoft Outlook 2013 directly opening a .eml message Using Outlook 1
M Opening Word Doc's in Adobe Acrobat Pro Using Outlook 9
L Opening up Contact from an Email - Outlook 2007 Using Outlook 15
0 Outlook 2010 causes computer to lose connection when opening and Send/Receive Using Outlook.com accounts in Outlook 14

Similar threads

Back
Top