MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Macro to send mail in Lotus Notes

Posted by Becky on August 22, 2001 9:34 AM

I would like to write a macro to send a message in lotus notes. This seems like it would be simple, but I am having trouble writing it.
This is what I would like it to do:
I will put an email address in cell Y1.
I will put a message in cell Z1.
I will attach a checkbox to the macro. When the checkbox is activated, the message in Z1 will be sent to the recipient in cell Y1.

Can anyone help me with this?

Thanks in advance for your help!!!!

Posted by Ivan F Moala on August 23, 2001 2:54 AM

This should help you out change as required
or post.

Sub LotusNotes_Session()
Dim Subject As String
Dim Recipient As String
Dim Msg As String
Dim nSession As notesSession
Dim nDatabase As NotesDatabase
'Need to reference the Lotusnotes object library

Subject = "Test message from VBA"
Recipient = ""
Msg = "This is a message sent to myself from VBA." + _
vbNewLine + "blah"

'session and database declared in general as object
Set nSession = CreateObject("Notes.NotesSession") 'create notes session
Set nDatabase = nSession.GetDatabase("", "") 'set db to database not yet named
Call nDatabase.OPENMAIL 'Open the users mail database

Set nDoc = nDatabase.CREATEDOCUMENT 'create a new document in mail database
Call nDoc.replaceitemvalue("SendTo", Recipient) 'create sendto field
Call nDoc.replaceitemvalue("Subject", Subject) 'create subject field
Call nDoc.replaceitemvalue("Body", Msg) 'create body field
Call nDoc.SEND(False) 'send message

Set nSession = Nothing ' close connection to free memory

End Sub

'Notes from help file;
'Set nDatabase = nSession.GetDatabase( server$, dbfile$ [, createonfail ] )


'String. The name of the server on which the database resides.
'Use an empty string ("") to indicate a database on the current computer:
'if the script runs on the workstation, the empty string indicates a local database;
'if the script runs on a server, it indicates a database on that server.


'String. The file name and location of the database within the Notes data directory.
'Use empty strings for both dbfile$ and server$ if you want to open the database later.
'Use a full path name if the database is not within the Notes data directory.


'Note This parameter is new with Release 5.

'Boolean. Optional. Specify True (default) to create the database if it does not exist.

'Return value

'A NotesDatabase object that can be used to access the database you've specified.

'If a database exists at the server$ and dbfile$ specified,
'the NotesDatabase object is open, and the script can access all its properties and methods.

'If a database does not exist at the server$ and dbfile$ specified,
'the NotesDatabase object is closed. To create a new database at the
'specified location if one does not exist, specify True for createonfail.