Exporting to excel

ok now bear with me while I share a couple of excelllent bits of code, both export views to excel through agents

‘’‘’‘’’

On Error Resume Next

Dim s As New notessession

Dim db As notesdatabase

Set db= s.currentdatabase

Dim uiw As New NotesUIWorkspace

Dim otherdoc As NotesDocument

Dim otherview As NotesView

Dim othercol As NotesDocumentCollection

Dim tempdoc As notesdocument

'Work out the current view’s name

Dim uiv As notesuiview

Set uiv = uiw.currentview

Call s.setenvironmentvar(“CurrentView”,“”)

Elseif uiv.viewalias <> “” Then 'use alias if it isn’t blank

currentviewname = uiv.viewalias

Else ’ use name

currentviewname = uiv.viewname

End If

'Get the view

Set otherview = db.GetView(currentviewname)

If otherview Is Nothing Then

Messagebox “Could not open the view. “”” & currentviewname & “”“”

Exit Sub

End If

'Check if it is for all documents or only selected

Set othercol = db.unprocesseddocuments

If othercol.count >1 Then 'if more than one doc selected then confirm

resp = Messagebox("Do you want to export only the " & _

“selected " & othercol.count & " documents?”, 36, “Selected only?” )

Else

Messagebox "Exporting all rows. (To export only selected " & _

“rows tick those required in the left margin first.)”

End If '6= yes

Dim object As NotesEmbeddedObject

Dim xlApp As Variant

Dim oWorkbook As Variant

Set xlApp = CreateObject(“Excel.Application”)

xlApp.Visible = True 'set to visible, this can be moved to the end if you wish

Set oworkbook = xlApp.Workbooks 'handle to Workbook

oworkbook.Add

'Stick out the column headers

hcolmn=1

Forall c In otherview.Columns

xlApp.cells(1,hcolmn) = c.title

hcolmn=hcolmn+1

End Forall

row=2

If resp=6 Then 'selected documents

Dim seldoc As notesdocument

Set seldoc = othercol.GetFirstDocument

While Not seldoc Is Nothing

If resp=6 Then

Set otherdoc = otherview.getnextdocument(seldoc)

If otherdoc Is Nothing Then

Set otherdoc = otherview.getprevdocument(seldoc)

If otherdoc Is Nothing Then

 Print " >1 doc should be selected"

 End

Else

 Set otherdoc = otherview.getnextdocument(otherdoc)

End If

Else 'got next doc

Set otherdoc = otherview.getprevdocument(otherdoc)

End If

End If

For colmn = 0 To Ubound(otherview.Columns)

xlApp.cells(row,colmn+1) = otherdoc.columnvalues(colmn)

Next

row=row+1

Set seldoc = othercol.GetNextDocument(seldoc)

Wend

Else ’ all documents

Set otherdoc = otherview.GetFirstDocument

While Not otherdoc Is Nothing

For colmn = 0 To Ubound(otherview.Columns)

xlApp.cells(row,colmn+1) = otherdoc.columnvalues(colmn)

Next

row=row+1

Set otherdoc = otherview.GetNextDocument(otherdoc)

Wend

End If

'this highlights the headings

xlApp.application.Rows(“1:1”).Select

With xlApp.application.Selection.Font

.bold = True

.ColorIndex = 48

.Name = “Arial”

.Size = 12

End With

'this freezes the panes

xlApp.application.Rows(“2:2”).Select

xlApp.application.ActiveWindow.FreezePanes = True

'this autofits the columns

xlApp.cells.select

xlApp.selection.Columns.AutoFit

xlApp.application.rows(“1:1”).Select

‘’‘’’

Now I have another one which exports selected folders to excel

‘’‘’‘’’

On Error Resume Next

Dim s As New notessession

Dim db As notesdatabase

Set db= s.currentdatabase

Dim uiw As New NotesUIWorkspace

Dim otherdoc As NotesDocument

Dim otherview As NotesView

Dim othercol As NotesDocumentCollection

Dim tempdoc As notesdocument

'Work out the current view’s name

Dim uiv As notesuiview

Set uiv = uiw.currentview

Call s.setenvironmentvar(“CurrentView”,“”)

Elseif uiv.viewalias <> “” Then 'use alias if it isn’t blank

currentviewname = uiv.viewalias

Else ’ use name

currentviewname = uiv.viewname

End If

'Get the view

Set otherview = db.GetView(currentviewname)

If otherview Is Nothing Then

Messagebox “Could not open the view. “”” & currentviewname & “”“”

Exit Sub

End If

'Check if it is for all documents or only selected

Set othercol = db.unprocesseddocuments

If othercol.count >1 Then 'if more than one doc selected then confirm

resp = Messagebox("Do you want to export only the " & _

“selected " & othercol.count & " documents?”, 36, “Selected only?” )

Else

Messagebox "Exporting all rows. (To export only selected " & _

“rows tick those required in the left margin first.)”

End If '6= yes

Dim object As NotesEmbeddedObject

Dim xlApp As Variant

Dim oWorkbook As Variant

Set xlApp = CreateObject(“Excel.Application”)

xlApp.Visible = True 'set to visible, this can be moved to the end if you wish

Set oworkbook = xlApp.Workbooks 'handle to Workbook

oworkbook.Add

'Stick out the column headers

hcolmn=1

Forall c In otherview.Columns

xlApp.cells(1,hcolmn) = c.title

hcolmn=hcolmn+1

End Forall

row=2

If resp=6 Then 'selected documents

Dim seldoc As notesdocument

Set seldoc = othercol.GetFirstDocument

While Not seldoc Is Nothing

If resp=6 Then

Set otherdoc = otherview.getnextdocument(seldoc)

If otherdoc Is Nothing Then

Set otherdoc = otherview.getprevdocument(seldoc)

If otherdoc Is Nothing Then

 Print " >1 doc should be selected"

 End

Else

 Set otherdoc = otherview.getnextdocument(otherdoc)

End If

Else 'got next doc

Set otherdoc = otherview.getprevdocument(otherdoc)

End If

End If

For colmn = 0 To Ubound(otherview.Columns)

xlApp.cells(row,colmn+1) = otherdoc.columnvalues(colmn)

Next

row=row+1

Set seldoc = othercol.GetNextDocument(seldoc)

Wend

Else ’ all documents

Set otherdoc = otherview.GetFirstDocument

While Not otherdoc Is Nothing

For colmn = 0 To Ubound(otherview.Columns)

xlApp.cells(row,colmn+1) = otherdoc.columnvalues(colmn)

Next

row=row+1

Set otherdoc = otherview.GetNextDocument(otherdoc)

Wend

End If

'this highlights the headings

xlApp.application.Rows(“1:1”).Select

With xlApp.application.Selection.Font

.bold = True

.ColorIndex = 48

.Name = “Arial”

.Size = 12

End With

'this freezes the panes

xlApp.application.Rows(“2:2”).Select

xlApp.application.ActiveWindow.FreezePanes = True

'this autofits the columns

xlApp.cells.select

xlApp.selection.Columns.AutoFit

xlApp.application.rows(“1:1”).Select

‘’‘’‘’‘’‘’‘’

Not knowing Lotus was able to do this I got quite excited…

Now my question was could you do this

run agent

Agent asks which folder(S) you would like to export

Agent asks which dates you would like to export for, today, today & today -1, etc

All emails received for specific days which are in specific folders are now exported to excel.

any pointers woudl be great, happy to lear code etc… only just discovered lotus could do something like this

regards

Alex

Subject: Exporting to excel

Yes, yes and yes.

You could define a dialog and call it with NotesUIWorkspace.DialogBox.

Subject: RE: Exporting to excel

ok superb… doesn’t mean anything to me now but at least I know what route to take thx