Automatically open link in email received

Nabeel Naveed

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi! Diane, are you still around? I would like to ask that, can I use the same procedure and scripts for Gmail account?
 

Nabeel Naveed

New Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Most of the time, yes. :)


As long as its in outlook, yes. If you are using automation to open the links and gmail is not the default account, you need to reference it, but its not difficult.
Thanks, I will try to implement this procedure for Gmail if need help will you able to assist me that would be a great favor.
 

fmissana

New Member
Outlook version
Outlook on the web
Email Account
Office 365 Exchange
Hi All,

I am a freelancer agent and I am less than a novice when it comes to coding so I need some help please. I receive jobs via email which contains 2 links. 1 to accept the job and the 2nd is to decline it.

As I am on the road it is difficult getting reception and checking emails every few minutes so I need a script that runs on my PC as outlook 2007 is always open, that will automatically click on the "accept" link. I have tried running rules, by detecting key words in the incoming message, but the only option I have is to run a script and I am hopeless at that sort of thing. I am happy to pay for the script through PayPal, it's just that I have a very small window of opportunity to accept the job in.

Any help would be greatly appreciated, thanks.

brilliant. It took me a while to figure out the shell command and having to remove the reference to IE, silly me. I told you I am less than novice when it comes to this sort of thing. I don't know how to thank you, you have been a blessing, thank you so much for taking the time and I am sorry if I caused any stress, God bless you I know I felt it.

Kindest Regards
Tony
Hello Tony, sounds like you are getting the same type of emails like I do (accept/decline, short time window). Do you mind sharing the steps and code you got in order to accept the jobs?
 

fmissana

New Member
Outlook version
Outlook on the web
Email Account
Office 365 Exchange
Hello Diane, as indicated I have a very similar problem as Tony (clicking on a specific link in an email to open a web page and then clicking on a radio button on that page to accept the job). As you indicated, I copy pasted the Open a specific hyperlink code in the ThisOutlookSession window, but when I run it, I get a compile error "sub or Function not defined" and the cursor highlights ShellExecute in the line starting with 1success. Do I need to add/modify anything?
Awaiting your kind response.
BR
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Did you add a reference to the Microsoft VBScript Regular Expressions library in Tools, References? (Error is usually earlier if you didn't)

Do you use outlook 64-bit? (error should be at the start though).
 

fmissana

New Member
Outlook version
Outlook on the web
Email Account
Office 365 Exchange
Did you add a reference to the Microsoft VBScript Regular Expressions library in Tools, References? (Error is usually earlier if you didn't)
> yes, I did
Do you use outlook 64-bit? (error should be at the start though).
> yes, I do
 

fmissana

New Member
Outlook version
Outlook on the web
Email Account
Office 365 Exchange
Hello Diane, I figured out what the problem was. In the "Open a specific hyperlink" code you suggested, there is a portion for 64bit Outlook versions that is commented out:
' 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

Since I am using a 64bit versin, I added PrtSafe after Declare in the second line, but I failed to delete the underscore at the end of the first line. So VBA was taking the whole thing as a comment and was not seeing the declaration of the ShellExecute function.

I took out the underscore at the end of the first line and now I no longer get the "sub or Function not defined" error.

However, the script is not doing anything. What Am I missing?
 

GermanUSer

Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Hello Diane,
I'm trying to get the script to running. The first link in the message must be clicked.
Unfortunately, it does not work or only partially. Is there any way to contact you via conversation or mail to explain it better?
I would be very grateful for your help!
 

GermanUSer

Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
probably somebody can help me to..
macro work for test, but i cant build a rule, scriptlist is empty..? i have screenshot here
any ideas please..?

Unbenannt.PNG
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
What exactly is happening - it works on some but not all messages? Any errors?

On the rule, the macro "title" needs to be formatted like this - specifically the bolded part.
Public Sub OpenLinks(olMail As Outlook.MailItem)

I have a macro that can work for testing, in place of a rule - select a message and run this macro. It will run the other macro.

Code:
Sub TestRunScript()
Dim objApp As Outlook.Application
Dim objItem As MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
OpenLinks objItem

End Sub
 

GermanUSer

Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server
Thanks for the answer!
Would you please help me further? The task is this: with new e-mail the first hyperlink must be opened. I have tried several scripts that are described here. But I do not get the job completely solved. I made that when testing the script works in VBA. But I can not run the script with Rule, because the script list stays empty, like in the picture. Or I can not test the script because the script name is missing. I have no idea how it works and try to copy / paste, but I can not get it. I tried that
Is it possible to contact you for help? probably with team viewer?
Many thanks





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

Set Reg1 = New RegExp

With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)"
.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)
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

Set Reg1 = Nothing
End Sub
 
Top