DreamDancer

Untitled

Oct 24th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' below requires a form with a textbox, and a button
  2. ' paste ANYTHING with email address's in it, and when you click the button
  3. ' ba da bing you get back a list of comma delimited email address's
  4. ' in case it's not obvious, the textbox is named "Stuff" and the button is "ExtractAddresses"
  5.  
  6. Option Explicit
  7.  
  8. Private Sub ExtractAddresses_Click()
  9. Dim Work As String, MiDx As Long, EmailList() As String, EiDx As Long
  10. Dim FindEmails As Object, Emails As Object, ValidEmail As String
  11.  
  12.   Work = LCase$(Stuff.Text)
  13.   If (Len(Work) > 0) Then
  14.     Set FindEmails = CreateObject("vbscript.regexp")
  15.     FindEmails.Global = True
  16.     FindEmails.IgnoreCase = True
  17.     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])?"
  18.     Set Emails = FindEmails.Execute(Work)
  19.     EiDx = 0
  20.     ReDim EmailList(EiDx)
  21.     If (InStr(1, Emails(0).Value, "@ripe.net", vbTextCompare) = 0) Then
  22.       EmailList(EiDx) = Emails(0).Value
  23.     End If
  24.     For MiDx = 1 To Emails.Count - 1
  25.       ValidEmail = Emails(MiDx).Value
  26.       If (Len(ValidEmail) > 0) Then
  27.         For EiDx = 0 To UBound(EmailList)
  28.           If (EmailList(EiDx) = Emails(MiDx).Value) Then Exit For
  29.         Next EiDx
  30.         If (EiDx > UBound(EmailList)) Then
  31.           ReDim Preserve EmailList(EiDx)
  32.           EmailList(EiDx) = Emails(MiDx).Value
  33.         End If
  34.       End If
  35.     Next MiDx
  36.     Work = Join$(EmailList, ", ")
  37.     Stuff.Text = Work
  38.   End If
  39. End Sub
Advertisement
Add Comment
Please, Sign In to add comment