gaurav1207
gaurav1207

Reputation: 703

extract multiple recipient email address from the Lotus Notes using VBA

I edited a VBA code that I got from the internet in order to fetch recipient email address and all email addresses from CC field. The code below is just showing only one email address, however there are multiple recipients. How can I edit the below program to get all recipients from SendTo and CopyTo fields.

Public Sub Get_Notes_Email_Address()
Dim NSession As Object      'NotesSession
Dim NMailDb As Object       'NotesDatabase
Dim NDocs As Object         'NotesDocumentCollection
Dim NDoc As Object          'NotesDocument
Dim NNextDoc As Object      'NotesDocument
Dim NItem As Object         'NotesItem
Dim view As String
Dim vn As Integer
Dim filterText As String

filterText = "text to search"

Set NSession = CreateObject("Notes.NotesSession")
'Set NMailDb = NSession.CurrentDatabase
Set NMailDb = NSession.getDatabase("<SERVERNAME>", "<LOCATION>")
'MsgBox NMailDb.AllEntries()

If Not NMailDb.IsOpen Then
    NMailDb.OPENMAIL
End If

Set NDocs = NMailDb.AllDocuments 

If filterText <> "" Then
    NDocs.FTSEARCH filterText, 0
End If
'MsgBox NDocs.Count
Set NDoc = NDocs.GetFirstDocument
'MsgBox NDocs.GetFirstDocument


vn = 2
Do Until NDoc Is Nothing
    Set NNextDoc = NDocs.GetNextDocument(NDoc)
    Set NItem = NDoc.GETFIRSTITEM("Body")
    If Not NItem Is Nothing Then
   
        Cells(vn, 3) = NDoc.GETITEMVALUE("Subject")(0)
        'MsgBox prompt:=NDoc.GETITEMVALUE("CopyTo")(0), Title:="CopyTo"
        Cells(vn, 4) = NDoc.GETITEMVALUE("CopyTo")
        'MsgBox prompt:=NDoc.GETITEMVALUE("SendTo")(0), Title:="SendTo"
        Cells(vn, 5) = NDoc.GETITEMVALUE("SendTo")
        
        
        
        
    End If
    Set NDoc = NNextDoc
    vn = vn + 1
   
    
Loop
'reset all objects to null
Set NMailDb = Nothing
Set NSession = Nothing

End Sub

Upvotes: 0

Views: 194

Answers (1)

Richard Schwartz
Richard Schwartz

Reputation: 14628

You are calling GetItemValue in this line:

Cells(vn, 4) = NDoc.GETITEMVALUE("CopyTo")

This function returns an array. Instead of retrieving it directly into the cell, you need to read it into a variable. You need to write a loop that examines this variable as an array -- copying the entries of this array, starting at subscript zero, into your cell.

Upvotes: 2

Related Questions