A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Tags: ,

Parse for URL's





 
 
Thread Tools Display Modes
  #1  
Old October 14th 06, 03:23 PM posted to microsoft.public.outlook.program_vba
Zigman53
external usenet poster
 
Posts: 1
Default Parse for URL's

I need to parse for URLs incoming mail from a specific sender and to
automatically run Internet Explorer on those URLs.

Any help out there?

Ads
  #2  
Old October 15th 06, 02:02 PM posted to microsoft.public.outlook.program_vba
Peter Marchert
external usenet poster
 
Posts: 208
Default Parse for URL's

Hello,

I have an old code snippet here and do not know, if it still works. Try
it and fit it to your requirements:

Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" _
(ByVal Hwnd As Long, ByVal lpOperation As String, ByVal lpFile As
String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long
Public Sub OpenHyperlink()


'================================================= ========================================
' Searching for Links in new mails and open them

'================================================= ========================================

' Show and activate the browser window
Const SW_SHOWNORMAL As Long = 1

' Senderaddress
Const SENDER As String = "



'-----------------------------------------------------------------------------------------
' Variables

'-----------------------------------------------------------------------------------------
Dim objInBox As Outlook.MAPIFolder ' Inbox
Dim objItems As Outlook.Items ' All mails
from senderaddress
Dim objItem As Object ' One single
mail

Dim strBody As String ' mail content
Dim strLink As String ' Hyperlink
Dim strFilter As String ' Filter

Dim lngReturn As Long ' Returnvalue
of "ShellExexute"


'-----------------------------------------------------------------------------------------
' Does not work on saturday (god`s sabbat)

'-----------------------------------------------------------------------------------------
If Format(Date, "DDDD") = "Saturday" Then Exit Sub


'-----------------------------------------------------------------------------------------
' Reference the inbox

'-----------------------------------------------------------------------------------------
Set objInBox = Nothing
Set objInBox = Outlook.session.GetDefaultFolder(olFolderInbox)


'-----------------------------------------------------------------------------------------
' Reference all mails from senderaddress

'-----------------------------------------------------------------------------------------
strFilter = "[SenderName] = """ & SENDER & """"
Set objItems = Nothing
Set objItems = objInBox.Items.Restrict(strFilter)


'-----------------------------------------------------------------------------------------
' No mails matching?

'-----------------------------------------------------------------------------------------
If objItems.Count = 0 Then Exit Sub


'-----------------------------------------------------------------------------------------
' Get the first item

'-----------------------------------------------------------------------------------------
Set objItem = Nothing
Set objItem = objItems.GetFirst


'-----------------------------------------------------------------------------------------
' Run all items

'-----------------------------------------------------------------------------------------
Do


'-------------------------------------------------------------------------------------
' Read the body

'-------------------------------------------------------------------------------------
strBody = objItem.Body


'-------------------------------------------------------------------------------------
' Get the hyperlink

'-------------------------------------------------------------------------------------
strLink = GetHyperlink(strBody)


'-------------------------------------------------------------------------------------
' Link found?

'-------------------------------------------------------------------------------------
If strLink "" Then


'---------------------------------------------------------------------------------
' Open link

'---------------------------------------------------------------------------------
lngReturn = ShellExecute(0, "open", strLink & vbNullChar,
vbNullString, _
vbNullString, SW_SHOWNORMAL)


'---------------------------------------------------------------------------------
' Delete the mail if open commando was successful

'---------------------------------------------------------------------------------
If lngReturn = 42 Then objItem.Delete

End If


'-------------------------------------------------------------------------------------
' Get the next item

'-------------------------------------------------------------------------------------
Set objItem = Nothing
Set objItem = GetNextItem(objItems)

Loop While Not objItem Is Nothing

End Sub
Private Function GetNextItem(objItems As Outlook.Items) As Object


'================================================= ========================================
' Returns the next item (if exists)

'================================================= ========================================

On Error Resume Next

Set GetNextItem = objItems.GetNext

End Function
Private Function GetHyperlink(ByVal strBody As String) As String


'================================================= ========================================
' Returns the first hyperlink in a mail (the hyperling have to be
on the beginning of a line)

'================================================= ========================================

Dim aryBody() As String
Dim intIndex As Integer


'-----------------------------------------------------------------------------------------
' Split body in rows

'-----------------------------------------------------------------------------------------
aryBody() = Split(strBody, vbCrLf)


'-----------------------------------------------------------------------------------------
' Does we have at least 1 row?

'-----------------------------------------------------------------------------------------
If UBound(aryBody()) -1 Then


'-------------------------------------------------------------------------------------
' Search the 1. hyperlink

'-------------------------------------------------------------------------------------
For intIndex = 0 To UBound(aryBody())


'---------------------------------------------------------------------------------
' Hyperlink found?

'---------------------------------------------------------------------------------
If Left(Trim(aryBody(intIndex)), 7) = "http://" Then


'-----------------------------------------------------------------------------
' Return hyperlink and get out

'-----------------------------------------------------------------------------
GetHyperlink = aryBody(intIndex): Exit Function

End If

Next

End If

End Function

--
Peter Marchert
[EDV-Service Marchert]
Homepage: http://www.marchert.de
Excel- und Outlookprogrammierung

Zigman53 schrieb:

I need to parse for URLs incoming mail from a specific sender and to
automatically run Internet Explorer on those URLs.

Any help out there?


  #3  
Old October 15th 06, 06:52 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,196
Default Parse for URL's

Am 15 Oct 2006 06:02:56 -0700 schrieb Peter Marchert:

Wow, Peter! For sure you'll win this year`s competition of who posts the
most lines :-)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
script to parse ip addresses from outlook headers JTL Outlook and VBA 1 July 27th 06 05:55 AM
URL's not clickable in email Bob Day Outlook - General Queries 2 May 13th 06 05:06 PM
Parse email headers John Smith Outlook and VBA 1 March 28th 06 08:46 PM
Parse .msg file Vadivel Outlook and VBA 5 March 16th 06 06:17 PM
Parse .msg file Vadivel Outlook - Using Forms 1 March 15th 06 04:26 PM


All times are GMT +1. The time now is 04:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2008 Outlook Banter, part of the NewsgroupBanter project.
The comments are property of their posters.
Loans - Problem Mortgage - Problem Mortgage - Problem Mortgage - Mortgage Calculator