John,
Thanks for the code.
I have it in the modules, but am getting "Invalid use of Null" This is the
code I have:
Private Sub Command35_Click()
Dim strEmail As String
Dim strExtract As String
Dim strContent As Variant
strContent = FileContents("e:\rep_temp.txt", False, 1)
strExtract = rgxExtract(strContent,
"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$")
strEmail = strExtract
olSendRpt strEmail, "Please see registration information below." & vbCrLf,
"Registration", "Registration"
End Sub
The file "e:\rep_temp.txt" has many words and dashes and then an email
address somewhere in the file. I am trying to extract that email address and
place in the strEmail part of the olSendRpt function.
Thanks again.
- Steve
John Nurick said:
Hi Steve,
The simplest way is to read the text file into a string variable and
then use a regular expression to find and extract the email address.
This will work fine for "ordinary" email addresses that look like
(e-mail address removed). (Things are *much* more
complicated if you need to find any syntactically valid email address
rather than just this common form.)
The FileContents() and rgxExtract() functions here
http://www.j.nurick.dial.pipex.com/Code/index.htm
will do most of the work. There's also a link on that page to
information about regular expressions.
There are some regular expressions for matching email addresses at
http://regexlib.com/Search.aspx?k=email