Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' below requires a form with a textbox, and a button
- ' paste ANYTHING with email address's in it, and when you click the button
- ' ba da bing you get back a list of comma delimited email address's
- ' in case it's not obvious, the textbox is named "Stuff" and the button is "ExtractAddresses"
- Option Explicit
- Private Sub ExtractAddresses_Click()
- Dim Work As String, MiDx As Long, EmailList() As String, EiDx As Long
- Dim FindEmails As Object, Emails As Object, ValidEmail As String
- Work = LCase$(Stuff.Text)
- If (Len(Work) > 0) Then
- Set FindEmails = CreateObject("vbscript.regexp")
- FindEmails.Global = True
- FindEmails.IgnoreCase = True
- FindEmails.Pattern = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
- Set Emails = FindEmails.Execute(Work)
- EiDx = 0
- ReDim EmailList(EiDx)
- If (InStr(1, Emails(0).Value, "@ripe.net", vbTextCompare) = 0) Then
- EmailList(EiDx) = Emails(0).Value
- End If
- For MiDx = 1 To Emails.Count - 1
- ValidEmail = Emails(MiDx).Value
- If (Len(ValidEmail) > 0) Then
- For EiDx = 0 To UBound(EmailList)
- If (EmailList(EiDx) = Emails(MiDx).Value) Then Exit For
- Next EiDx
- If (EiDx > UBound(EmailList)) Then
- ReDim Preserve EmailList(EiDx)
- EmailList(EiDx) = Emails(MiDx).Value
- End If
- End If
- Next MiDx
- Work = Join$(EmailList, ", ")
- Stuff.Text = Work
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment