PDA

View Full Version : Cant send to multiple recipient using Lotus Notes VBA. Please help



Ajohneus
09-07-2015, 03:05 AM
Hi Everyone,

I want to send to multiple email address and it seems that the , or ; (comma and semi-colon) is not working. I can send using a single email though.

Any help would be greatly appreciated. Here are my codes.




Sub SendWithLotus()
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, vaMsg As Variant


Const EMBED_ATTACHMENT As Long = 1454
Const stTitle As String = "Active workbook status"
Const stMsg As String = "The active workbook must first be saved " & vbCrLf _
& "before it can be sent as an attachment."
'Check if the active workbook is saved or not
'If the active workbook has not been saved at all.
If Len(ActiveWorkbook.Path) = 0 Then
MsgBox stMsg, vbInformation, stTitle
Exit Sub
End If
'If the changes in the active workbook have been saved or not.
If ActiveWorkbook.Saved = False Then
If MsgBox("Do you want to save the changes before sending?", _
vbYesNo + vbInformation, stTitle) = vbYes Then _
ActiveWorkbook.Save
End If
'Get the name of the recipient from the user.
Do
vaRecipient = Application.InputBox( _
Prompt:="Please add email address of recipient: " & vbCrLf _
& "Enter email", _
Title:="Recipient", Type:=2)
Loop While vaRecipient = ""
'If the user has canceled the operation.
If vaRecipient = False Then Exit Sub
'Get the message from the user.
Do
vaMsg = Application.InputBox( _
Prompt:="Please enter the message such as:" & vbCrLf _
& "'Please find Report for NAME of SHOW + DATE TODAY.'", _
Title:="Message", Type:=2)
Loop While vaMsg = ""


'If the user has canceled the operation.
If vaMsg = False Then Exit Sub
'Add the subject to the outgoing e-mail
'which also can be retrieved from the users
'in a similar way as above.
Do
stSubject = Application.InputBox( _
Prompt:="Please add a subject such as:" & vbCrLf _
& "'SHOW101-01-2015.'", _
Title:="Subject", Type:=2)
Loop While stSubject = ""
'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.
If noDatabase.IsOpen = False Then noDatabase.OPENMAIL
'Create the e-mail and the attachment.
Set noDocument = noDatabase.CREATEDOCUMENT
Set obAttachment = noDocument.CREATERICHTEXTITEM("stAttachment")
Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.SendTo = vaRecipient
.Subject = stSubject
.Body = "Please see attached PPRF for Contract Preparation. Thanks and have a good one!"
.SaveMessageOnSend = True
End With
'Send the e-mail.
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
End Sub

Ajohneus
09-07-2015, 07:48 PM
I got the codes from my inquiry in forum. however when I try to enter several emails my lotus notes get a failure to deliver. Is it the code or Lotus.

Sorry, I'm a newbie

mancubus
09-08-2015, 02:00 AM
please use code tags when posting your code here.


it seems the code is from http://www.rondebruin.nl/win/s1/notes/notes8.htm or another related page

and this site tells you how to add multiple recipients..



'Retrieve the list of recipients.
With wsSheet
lnLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
vaRecipients = .Range("A1:A" & lnLastRow).Value
End With


so basically you need an array to hold the multiple email adresses.
above code gets the list from a range. you can do the same.
or create an array like:



Dim vaRecipients(2) As Variant
vaRecipients(0) = "Email_1"
vaRecipients(1) = "Email_2"
vaRecipients(2) = "Email_3"