Export Selected Docs To Excel

Learn how to export selected docs to Microsoft Excel.

This code will take the value of the document field specified in the view columns for the selected documents in

the view and place the values in the Excel spread sheet cells.

Create a View Action button and put the follwing code.

Export Selected Docs to Excel

Sub Click(Source As Button)
Dim s As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim dc As notesdocumentcollection
Dim doc As notesdocument
Dim vcols As Variant
Dim Uvcols As Integer
Set db = s.currentdatabase
Set dc = db.unprocesseddocuments
Set view = db.getview("PC\Lease Requests\Master")
Uvcols = Ubound(view.Columns)
Dim xlApp As Variant
Dim xlsheet As Variant
Set xlApp = CreateObject("Excel.Application")
xlApp.StatusBar = "Creating WorkSheet. Please be patient..."
xlApp.Visible = True
xlApp.Workbooks.Add
xlApp.ReferenceStyle = 2
Set xlsheet = xlApp.Workbooks(1).Worksheets(1)
xlsheet.Name = "PC Lease "
Dim rows As Integer
rows = 1
Dim cols As Integer
cols = 1
Dim maxcols As Integer
For x=0 To Ubound(view.Columns)
xlApp.StatusBar = "Creating Cells and Creating Cell Headings. Please
be patient..."
If view.Columns(x).IsHidden = False Then
If view.Columns(x).Title <> "" Then
xlsheet.Cells(rows,cols).Value = view.Columns(x).Title
cols = cols + 1
End If
End If
Next
maxcols = cols - 1

Set doc = dc.getfirstdocument
Dim fieldname As String
Dim fitem As notesitem
rows=2
cols=1

Do While Not (doc Is Nothing)
For x=0 To Ubound(view.Columns)
xlApp.StatusBar = "Importing Data from Lotus Notes Application.
Please be patient..."
If view.Columns(x).IsHidden = False Then
If view.Columns(x).Title <> "" Then
fieldname = view.Columns(x).Itemname
Set fitem = doc.getFirstItem(fieldname)
xlsheet.Cells(rows,cols).Value = fitem.Text
cols = cols+1
End If
End If
Next
rows = rows+1
cols =1
Set doc = dc.getnextdocument(doc)
Loop
xlApp.Rows("1:1").Select
xlApp.Selection.Font.Bold = True
xlApp.Range(xlsheet.Cells(1,1), xlsheet.Cells(rows,maxcols)).Select
xlApp.Selection.Font.Name = "Arial"
xlApp.Selection.Font.Size = 9
xlApp.Selection.Columns.AutoFit
With xlApp.Worksheets(1)
.PageSetup.Orientation = 2
.PageSetup.centerheader = "Report - Confidential"
.Pagesetup.RightFooter = "Page &P" & Chr$(13) & "Date: &D"
.Pagesetup.CenterFooter = ""
End With
xlApp.ReferenceStyle = 1
xlApp.Range("A1").Select
xlApp.StatusBar = "Importing Data from Lotus Notes Application was
Completed."
End Sub

This was first published in November 2000

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close