Microsoft Excel

Ron de Bruin
Excel Automation

Microsoft MVP Program

Lotus Notes: Retrieve e-mailaddresses from a Notes database

The code examples on this page are created by Excel MVP Dennis Wallentin but are not on his site anymore. But Dennis allow me to publish it on my site for all the Excel/Lotus Notes users in the world.

The information in this article applies to:
Microsoft Excel 2000 and later.
Lotus Notes 4.x and later.

External reference:

Microsoft ActiveX Data Objects 2.5 Library and above.
Lotus NotesSQL-driver for download: NotesSQL

Task:
Retrieve e-mailaddresses from a Notes database and dump the data into a worksheet.

VBA code :

Option Explicit
 
Sub Retrieve_E_Mailaddresses_Notes_Database()
   Dim cnt As ADODB.Connection
   Dim rst As ADODB.Recordset
   Dim xlCalc As XlCalculation
   Dim wbBook As Workbook
   Dim wsSheet As Worksheet
   Dim rnData As Range
 
   'One easy way to get the fieldnames in the database
   'is to create a query by using MS Query.
   Const stSQL As String = "SELECT MailAddress FROM Person ORDER BY MailAddress"
 
   With Application
      xlCalc = .Calculation
      .Calculation = xlCalculationManual
      .EnableEvents = False
      .ScreenUpdating = False
   End With
 
   Set wbBook = ThisWorkbook
   Set wsSheet = wbBook.Worksheets(1)
 
   With wsSheet
      Set rnData = .Range("A2")
   End With
 
   'Instantiate the Connectionobject.
   Set cnt = New ADODB.Connection
 
   'Open the connection.
   cnt.Open ("Driver={Lotus NotesSQL Driver (*.nsf)};Database=names.nsf;Server=Local;")
 
   'Instantiate the Recordsetobject and execute the query.
   Set rst = cnt.Execute(stSQL)
 
   'Dump the recordset into the worksheet.
   rnData.CopyFromRecordset rst
 
   rst.Close
   cnt.Close
 
   'Release objects from memory.
   Set cnt = Nothing
   Set rst = Nothing
 
   With Application
      .Calculation = xlCalc
      .EnableEvents = True
      .ScreenUpdating = True
   End With
 
End Sub

Comments:
A relative easy and straightforward way to retrieve data from a Notes database.