PDA

View Full Version : Open a dynamic URL using VBA in a Rule



nbardach
04-20-2012, 11:43 AM
Hi VBAXers,
I'm hoping someone can help me with this coding challenge. I would like to create a rule to help me integrate email from a third-party (a messenger service) into my order-tracking application using a dynamic URL.

Here is a synopsis of the rule I would like to create...

When an email is received from a specific sender, I need to parse the subject and open a dynamic URL in order to integrate with my web application:


Email received from "orders @ messenger . com"
Email Subject is "Order 123 has been delivered"
URL opens to "www . mysite. com/ EmailProcessor.aspx ? oid=123 & status=delivered "Can anyone help me with this challenge or point me to a resource?

Many thanks in advance! Noah

JP2112
05-07-2012, 12:51 PM
Using http://support.microsoft.com/kb/306108 as a guide for how to format the script:

Sub GotoURL(Item As Outlook.MailItem)

Dim emailSubject As String
Dim orderNumber As String
Dim url As String

On Error GoTo ErrorHandler

If TypeName(Item) = "MailItem" Then
' get order number
emailSubject = Item.Subject
orderNumber = Split(emailSubject, " ")(1)

url = http://www.mysite.com/EmailProcessor.aspx?oid= & orderNumber & "&status=delivered"
' use http://www.vbaexpress.com/forum/archive/index.php/t-536.html to follow hyperlink
End If

ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub

This script should be used as a rule for when emails arrive from the specified email address.