Subject: RE: Export to Excel…
Here is a snippet of code that I use to run a mail merge. How you get your documents is up to you. A view by date might work OK, or you can use John’s suggestion of getting a NotesDocumentCollection via a date range.
By the way, this is a very advanced programming task. I would do everything in my power to get the boss to wait.
Dim officeApp As Variant
Dim xlApp As Variant
Dim xlsheet As Variant
Dim array As Variant
Dim lname As String
Dim fname As String
Dim k As Integer
Dim IsFirstTry As Integer
Dim WindowsDirectory As String
WindowsDirectory = Environ("Windir")
Set domSes = New NotesSession
Set domDb = domSes.CurrentDatabase
'Unprocessed Documents is the key to finding selected documents
Set domColl = domDb.UnprocessedDocuments
Set domDoc = domColl.GetFirstDocument
If domColl.Count = 0 Then
Messagebox " At least one document must be selected in the view.",16,"Application Error"
Exit Sub
End If
Set xlApp = CreateObject("Excel.application")
xlApp.Workbooks.Add
Set xlsheet = xlApp.Workbooks(1).Worksheets(1)
'Write column titles
With xlsheet
.range("A1") = "RowTitle1"
.range("B1") = "RowTitle2"
.range("C1") = "RowTitle3"
.range("D1") = "RowTitle4"
'etc, etc, etc.
End With
k = 1 'k keeps track of the row number
While Not (domDoc Is Nothing)
k = k + 1
'write dataset to Excel worksheet
With xlsheet
.range("A" & k) = domDoc.Field1(0)
.range("B" & k) = domDoc.Field2(0)
.range("C" & k) = domDoc.Field3(0)
'etc, etc, etc.
End With
End With
Set domDoc = domColl.GetNextDocument(domDoc)
Wend
'The next section sorts the worksheet by Column H, then Column I. Delete if you don't need.
xlsheet.cells.select
xlapp.selection.sort xlsheet.range(“H1”) , 1 , xlsheet.range(“I1”) , , 1 , , , 1 , 1, False , 1, 0, 0, 0
'if statement deletes the file if it already exists - I am overwriting the same file each time
If Dir$( WindowsDirectory + “\temp\envsource.xls”) <> “” Then
Kill Environ("Windir") + "\temp\envsource.xls"
End If
On Error Goto 0
xlapp.activeworkbook.saveas WindowsDirectory + “\temp\envsource.xls”
xlapp.activeworkbook.close
xlapp.quit
xlapp = “”