Export View to Excel

Print the contents of any Notes view to Excel with the click of a button. The code is totally dynamic in R5, in R4 you have to make one small change.
 Sub Click(Source As Button)
	Dim WS As notesuiworkspace
	Dim UiView As notesuiview
	Dim ViewString As String
	Dim session As NotesSession
	Dim db As NotesDatabase 
	Dim v As NotesView
	Dim docX As NotesDocument
	Dim col As Integer
	Dim row As Double
	Dim xl As Variant
	Dim xlWbk As Variant
	Dim pagename As String
	Set WS = New notesuiworkspace
	Set session = New notessession
	Set db=session.CurrentDatabase
	Print "Please Be Patient as the Excel Spreadsheet is being created..."
' Get dynamic view name, R5 only
' Take this part out if using in R4, you have to hard-code the name of the view in ViewString
	Set UiView=WS.currentview
	Set v=db.GetView(ViewString)
' Create Excel Sheet
	Set xl=CreateObject("Excel.Application")
	Set xlWbk=xl.Workbooks.Add
' Add column headings to first row
	Forall vColumn In v.Columns
		xlWbk.ActiveSheet.Cells(1, col)=vColumn.Title
	End Forall
' Add row data from the documents
	Set docX=v.GetFirstDocument
	While Not docX Is Nothing
		Forall cValue In docX.ColumnValues
			xlWbk.ActiveSheet.Cells(row, col)=cValue
		End Forall
		Set docX=v.GetNextDocument(docX)
' Make all columns fit
	Print "Excel Document Successfully Created!"
' Open it up in Excel
End Sub

This was first published in March 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.