Email from Excel via VBA through Lotus Notes with attachments

Bengt

Active Member
Joined
Mar 4, 2008
Messages
267
Hi,
I am trying to send email from EXCEL/VBA through Lotus Notes and to attach files to the email that I send. After having checked a few fora, I know now how do the email thing, and I also know how to attach one file to the mail, but how do I do to attach any number of files?

The code I use looks something like this:
I have it in a function, so all the necessary info about recipient, subject and the name of the file that I want to attach etc is passed through the arguments of this function.

Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = Bodytext
MailDoc.SAVEMESSAGEONSEND = SaveIt

'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If


'Send the document
The section in red are the statements I use to attach the file, the name of which is in the string Attachment. But how do I do attach more files?

Grateful for any help

Bengt
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Thank you Andrew. I was able to use a variant of the code that I found on the link that you suggested.

Bengt
 
Upvote 0
Hi Bengt
I need please your help to send the current saved file to a lotus notes (this is my default email program); I need to use vlookup formula for the recipient, I don't want to send the email just the step to press the send botton , this will allow me to verify every thing befor sending the email.

Hi,
I am trying to send email from EXCEL/VBA through Lotus Notes and to attach files to the email that I send. After having checked a few fora, I know now how do the email thing, and I also know how to attach one file to the mail, but how do I do to attach any number of files?

The code I use looks something like this:
I have it in a function, so all the necessary info about recipient, subject and the name of the file that I want to attach etc is passed through the arguments of this function.

Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = Bodytext
MailDoc.SAVEMESSAGEONSEND = SaveIt

'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
'MailDoc.CREATERICHTEXTITEM ("Attachment")
End If


'Send the document
The section in red are the statements I use to attach the file, the name of which is in the string Attachment. But how do I do attach more files?

Grateful for any help

Bengt
 
Upvote 0
I am stil confused I just need a simple macro to send to lotus note the currrent saved excel file, the recipient address and msg title are found in A6 and B6 ,the message body is fixed. Can any one help
 
Upvote 0
Hi, I`m using excel 2013 with the Lotus Notes. I tried to send an e-mail and attach one file. The e-mail is sent, but without attachment. Here is the hole code i use:
Code:
 Sub nomifiles()  ' ' Scrive l'elenco dei nomi dei files contenuti nella directory '    Dim sFile                       As String    Dim fogli                       As String    Dim riga                        As Long     fogli = Range("B1").Value    If Right(fogli, 1) <> "\" Then fogli = fogli & "\"     riga = 7    ' Pulisce l'elenco    With Sheets("Data")       .Range("C7", .Range("C7").End(xlDown)).ClearContents       ' Cerca in tutti i files nella directoy source       sFile = Dir(fogli & "\*.xls")       If sFile <> "" Then          Do While sFile <> ""             .Range("C" & riga).Value = sFile             riga = riga + 1             sFile = Dir()          Loop       Else          MsgBox "Non ci sono files."       End If    End With End Sub  Sub LotusMail() ' ' Invio via Mail Lotus Notes dei files '  ' setting up various objects Dim Maildb As Object Dim UserName As String Dim MailDbName As String Dim MailDoc As Object Dim attachME As Object Dim Session As Object Dim EmbedObj1 As Object Dim recipient As String Dim ccRecipient As String Dim bccRecipient As String Dim subject As String Dim bodytext As String Dim Attachment As Object  For riga = 7 To 100   indirizzo = "A" & riga   oggetto = "B" & riga   allegato = "C" & riga      ' setting up all sending recipients   recipient = ThisWorkbook.Worksheets("Data").Range(indirizzo).Value   ccRecipient = ThisWorkbook.Worksheets("Data").Range("B3").Value   'bccRecipient = ""   subject = ThisWorkbook.Worksheets("Data").Range(oggetto).Value   bodytext = ThisWorkbook.Worksheets("Data").Range("B2").Value    '// Lets check to see if form is filled in Min req =Recipient, Subject, Body Text   If recipient = vbNullString Or recipient = "0" Or subject = vbNullString Or bodytext = vbNullString Then      MsgBox "Recipient, Subject and or Body Text is NOT SET! in row " & riga, vbCritical + vbInformation      Exit Sub   End If    ' creating a notes session   Set Session = CreateObject("Notes.NotesSession")   UserName = Session.UserName   MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"   Set Maildb = Session.GETDATABASE("", MailDbName)    If Maildb.IsOpen <> True Then      On Error Resume Next      Maildb.OPENMAIL   End If    Set MailDoc = Maildb.CreateDocument   MailDoc.Form = "Memo"    ' loading the lotus notes e-mail with the inputed data   With MailDoc      .SendTo = recipient      .copyto = ccRecipient      '.blindcopyto = bccRecipient      .subject = subject      .Body = bodytext   End With    ' saving message   MailDoc.SaveMessageOnSend = True    Attachment = ThisWorkbook.Worksheets("Data").Range(allegato).Value  If Attachment1 <> "" Then Set attachME = MailDoc.CREATERICHTEXTITEM("Attachment") Set EmbedObj = attachME.EMBEDOBJECT(1454, "", Attachment, "Attachment") 'MailDoc.CREATERICHTEXTITEM ("Attachment") End If    ' send e-mail !!!!   MailDoc.PostedDate = Now()   ' if error in attachment or name of recipients   On Error GoTo errorhandler1    MailDoc.Send 0, recipient    Set Maildb = Nothing   Set MailDoc = Nothing   Set attachME = Nothing   Set Session = Nothing   Set EmbedObj1 = Nothing  Next  'Unload Me Exit Sub ' setting up the error message errorhandler1: MsgBox "Incorrect name supplied or the attachment has not attached," & _ "or your Lotus Notes has not opened correctly. Recommend you open up Lotus Notes" & _ "to ensure the application runs correctly and that a vaild connection exists"  Set Maildb = Nothing Set MailDoc = Nothing Set attachME = Nothing Set Session = Nothing Set EmbedObj1 = Nothing ' unloading the userform 'Unload Me  End Sub
 
Upvote 0
Dir returns only the filename, so that's all you have in column C. When attaching the file you need to include its path.
 
Upvote 0

Forum statistics

Threads
1,215,564
Messages
6,125,579
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top