Outlook VBA snippets


E-mail en naam extraheren uit geëxporteerd .CSV-bestand van MailBox.

01Sub readCSV()
02 
03    Dim strBestand As String
04    Dim strRegel As String
05     
06    Dim objRegExEmail As Object
07    Dim objRegExEmailNaam As Object
08    Dim strEmail
09    Dim strEmailNaam
10     
11'   Via regular expression e-mail en naam extraheren
12    Set objRegExEmail = CreateObject("VBScript.RegExp")
13    Set objRegExEmailNaam = CreateObject("VBScript.RegExp")
14     
15'   Regular expression patronen
16    objRegExEmail.Pattern = "[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-zA-Z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
17    objRegExEmailNaam.Pattern = ":\s*(.*?)\s*[[<]"
18     
19'   Geexporteerd Outlook .csv-bestand inlezen
20    strBestand = ThisWorkbook.Path & Application.PathSeparator & "bron.csv"
21      
22    Open strBestand For Input As #1
23        Do
24            Line Input #1, strRegel
25             
26            If InStr(1, strRegel, "@") And InStr(1, strRegel, "Van: ") Then
27                 
28                Debug.Print "Regel: " & vbTab & strRegel
29                 
30                If objRegExEmail.Test(strRegel) Then
31'                   Standaardwaarde regular expression
32                    Set strEmail = objRegExEmail.Execute(strRegel)
33                    Debug.Print "E-mail: " & vbTab & strEmail(0).Value
34                End If
35                 
36                If objRegExEmailNaam.Test(strRegel) Then
37'                   Groepswaarde (submatch) regular expression
38                    Set strEmailNaam = objRegExEmailNaam.Execute(strRegel)
39                    Debug.Print "Naam: " & vbTab & vbTab & strEmailNaam(0).Submatches.Item(0)
40                End If
41                 
42                Debug.Print vbNewLine
43                 
44            End If
45             
46        Loop While Not EOF(1)
47 
48    Close #1
49     
50End Sub

alternatief: https://www.msoutlook.info/question/869