Hi excel experts, I was looking for some code to be able to send Lotus email with VBA. There were some useful codes (the best I found is below), but I can send email only to one recipient and without copy recipient, so its needs to be utilized, please help. I see in another code example that they are using string for vaRecipient nor Variant, but when I change it, it didn't work !
'The procedure for executing the main task:
Sub SendMail()
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 = "Status Active workbook"
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 has 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 the name of the recipient such as:" & vbCrLf _
& "excel@microsoft.com or just the name if it's internally.", _
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 text of message:", _
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 enter the subject of message:", _
Title:="Message", Type:=2)
Loop While stSubject = ""
'If the user has canceled the operation.
If stSubject = False Then Exit Sub
'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 = vaMsg
.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
THIS IS THE PART OF CODE I TRIED TO IMPLEMENT BUT WITHOUT SUCCESS, ANY SUGGESTIONS ???
Dim Rec As String, Recip() As String
Dim cc As String, CCrecip() As String
'Get the name of recipient
Rec = 1
ReDim Recip(0)
Do While Rec <> ""
Rec = InputBox("Enter recipient, or press cancel key")
If Rec <> "" Then
Recip(UBound(Recip)) = Rec
ReDim Preserve Recip(UBound(Recip) + 1)
End If
Loop
'Get name of CC recipient if any
cc = 1
ReDim CCrecip(0)
Do While cc <> ""
cc = InputBox("Enter copy recipient, or press cancel key")
If cc <> "" Then
CCrecip(UBound(CCrecip)) = cc
ReDim Preserve CCrecip(UBound(CCrecip) + 1)
End If
Loop
AND HERE IS THE PART FROM THE END WHERE THE WHOLE EMAIL IS CREATED
'Add values to the created e-mail main properties.
With noDocument
.Form = "Memo"
.sendto = Rec
.cc = cc
.Subject = stSubject
.Body = vaMsg
.SaveMessageOnSend = True
End With
'Send the e-mail.
With noDocument
.PostedDate = Now()
.Send 0, Rec
.Send 0, cc
End With
THANKS IN ADVANCE FOR YOUR COOPERATION, I THING THAT THIS THREAT (WHEN SOLVED) CAN BE ALSO USEFUL TO OTHER USERS...
Bookmarks