In general, there is only one email address, however I dont understand how I
can apply this code to multiple word documents.
Ideally I need the result to list the file name and the extracted email
address.
"Ron Rosenfeld" wrote:
On Mon, 22 Dec 2008 08:15:01 -0800, Matt Bennette
wrote:
The strings would be of differing lengths, so how would wild card work is
there a specific syntax i.e *?*@*?*.*?*. And what about VBA referencing Word
Commands to perform this
I don't know about "VBA referencing Word Commands"
The following uses Regular Expressions:
Is there only one email address per file? Or could there be multiple email
addresses in a file.
Here is a routine which, when applied against a text string of unspecified
length, will return the first string that looks like an email address. The
pattern does NOT contain all the rules for validating an email address, but
perhaps this method will get you started. Post back with more questions as
needed.
=====================================
Option Explicit
Public Const str As String = "now is the time for "
'--------------------------------------
Sub ExtrEmail()
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = True
re.Pattern = "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
If re.test(str) = True Then
Set mc = re.Execute(str)
Debug.Print mc(0).Value
End If
End Sub
==================================
--ron