问题
I have 'column A' with different names. I have all this people email contacts in my lotus notes account. I want to send an email to multiple recipients (to the people including in column A). I mean:
column A:
Ludvig Simpson
Matthew Ricky
Anne Cameron
etc...
And for example Ludvig Simpson has this lotus email address: dbyw4680, Matthew Ricky has cjua321 and Anne Cameron has ofdb1621. All this email addresses are found only in my lotus account.
My question: How can I send an email to Ludvig, Matthew and Anne??(I mean how to take automatically their address email from lotus?). To specify, the names in 'column A' are the same with the names in my lotus account.
I don't want to put their email addresses in a range/column one by one because the people name list is dinamic, changes, can grows.
Have you any idea?
Here is my code that send message to a multiple recipient taken from column A:
Sub sendEmail()
Dim noSession As Object, noDatabase As Object, noDocument As Object
Dim obAttachment As Object, EmbedObject As Object
Dim stSubject As Variant, stAttachment As String
Dim vaRecipient As Variant
Dim vaMsg As Variant
Const EMBED_ATTACHMENT As Long = 1454
Const stTitle As String = "Status Active workbook"
Const stMsg As String = "The active workbook must first be saved " & vbCrLf _
& "before it can be sent as an attachment."
'If the active workbook has not been saved at all.
If Len(ActiveWorkbook.Path) = 0 Then
MsgBox stMsg, vbInformation, stTitle
Exit Sub
End If
Dim x As Integer
For x = 1 To Cells(Rows.Count, "A").End(xlUp).Row
'Get the name of the recipient from the user.
vaRecipient = Worksheets("Sheet1").Range("A" & x).Value
Do 'Get the message from the user.
vaMsg = "My email text"
Loop While vaMsg = ""
If vaMsg = False Then Exit Sub 'If the user has canceled the operation.
'Add the subject to the outgoing e-mail which also can be retrieved from the users
'in a similar way as above.
stSubject = "My subject email"
'Retrieve the path and filename of the active workbook.
stAttachment = ActiveWorkbook.FullName
'Instantiate the Lotus Notes COM's Objects.
Set noSession = CreateObject("Notes.NotesSession")
Set noDatabase = noSession.GETDATABASE("", "")
'If Lotus Notes is not open then open the mail-part of it.
On Error Resume Next
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail
Set noDocument = noDatabase.CreateDocument
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.sendto = vaRecipient
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
End With
'Send the e-mail.
Dim myMessage As String
myMessage = MsgBox("Are you sure you want to send the email?", vbYesNo, "Are you sure?")
If myMessage = vbYes Then
With noDocument
.PostedDate = Now()
.SEND 0, vaRecipient
End With
'Release objects from the memory.
Set EmbedObject = Nothing
Set obAttachment = Nothing
Set noDocument = Nothing
Set noDatabase = Nothing
Set noSession = Nothing
'Activate Excel for the user.
AppActivate "Microsoft Excel"
MsgBox "The e-mail has successfully been created and distributed.", vbInformation, "Done!"
Else
MsgBox "Unsent email!", vbInformation, "Unsent email"
End If
Next x
End Sub
来源:https://stackoverflow.com/questions/25934183/send-email-to-a-specific-lotus-notes-contacts-using-vba