VBA Help Needed - Excel to Lotus Notes (email)

gkisystems

Board Regular
Joined
Apr 20, 2012
Messages
76
I have the following macro that works fine except for 1 exception - it does not enter any text as the body of the message. How can I edit this code so it includes a message for the body of the email?


Sub EmailRDReport()
'Working in Excel 2010 with Lotus Notes
Dim wb As Workbook
Dim I As Long


Set wb = ActiveWorkbook


If Val(Application.Version) >= 12 Then
If wb.FileFormat = 51 And wb.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If


On Error Resume Next
For I = 1 To 3
wb.sendmail "emailaddress1@example.com, emailaddress2@example.com, emailaddress3@example.com", _
"My Subject Line Goes Here"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I am not aware of any way to use the workbook functionality to define the body of an email.

Try adding a reference to Lotes Notes in the VB Editor and accessing it directly. The object library should have a Document object which has a Body property I believe that lets you set the body of the email. If you need specific code reply back and I will dig it up for you, I have a number of spreadsheets at work that send emails via Lotes Notes.
 
Upvote 0
I am not aware of any way to use the workbook functionality to define the body of an email.

Try adding a reference to Lotes Notes in the VB Editor and accessing it directly. The object library should have a Document object which has a Body property I believe that lets you set the body of the email. If you need specific code reply back and I will dig it up for you, I have a number of spreadsheets at work that send emails via Lotes Notes.

I believe there is code that allows you to define the body of the email. I found this website that offers some tips, except the VBA code that is offered that includes a message in the body of an email only works with Outlook, not Lotus Notes. See here:

Example Code for sending mail from Excel

Would you be able to give me the specific code that would work by adding a reference to Lotes Notes in the <acronym title="vBulletin" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VB</acronym> Editor? I'm no expert on VBA, I'm just learning as I go and so far I'm only skilled in making minor changes to existing code...not creating new code from scratch.
 
Upvote 0
Here is the code I use.
Code:
Sub SendEMail(Recipient As Variant, Subject As String, Body As String)
  Dim notesSession As Object, notesDatabase As Object, notesDocument As Object
  Set notesSession = CreateObject("Notes.NotesSession")
  Set notesDatabase = notesSession.GETDATABASE("", "")
  If notesDatabase.IsOpen = False Then notesDatabase.OPENMAIL
  Set notesDocument = notesDatabase.CreateDocument  
  With notesDocument
    .Form = "Memo"
    .SendTo = Recipient
    .Subject = Subject
    .Body = Body
    .SaveMessageOnSend = False
  End With
  With notesDocument
    .PostedDate = Now()
    .Send 0, Recipient
  End With
End Sub
Recipients is aways an array of strings which are the email addresses.
 
Upvote 0

Forum statistics

Threads
1,215,301
Messages
6,124,146
Members
449,144
Latest member
Rayudo125

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