Still not sure how to write coding to export category

I got the following script to export category , however my efforts to modify it to my requirement is still futile currently. what I want is just for database to pick up categorised total values from a view, and paste it into a template, which I saved in my Page Element. i.e:

MyView: Jan Feb

Category 1 30 50

SubCateg1 10 40

SugCateg2 20 10

Category 2 30 60

*for category 2, I collapsed at the highest level.

I was made to understand that there is no way I can write a script to collapsed or expand at certain level, thus, my process will be follow:

  1. collapse and expand relevant doument manually via clicking the twisties on the left hand side

  2. click the button on the view,which will

a. go to MyView, get total values of Jan and Feb for Categ1, SubCateg1, subcateg2, and categ2,

b. go to page element, and select an excel attached file, and paste it to cell B2, C2, for Categ1, B3-B4 and C3-C4 to subcateg1-3. and B7-B8 for Categ2.

I hoped someone can guide me how do i modify the code below for above needs, currently, I keep getting object variable not defined ,altough I created "Keywords"view, and a document with first column displaying “Invoice Aging Template”. But i don’t understand what name of excel file should I attached, and whether any formating required.

thank you.

Here is an example:

This agent gets a template from a lookupdoc then gets a categorized view and interates through the view getting values from the view (including totals from the categories).

Sub Initialize

On Error Goto endroutine

Dim s As New Notessession

Dim db As Notesdatabase

Set db = s.currentdatabase

Dim view As NotesView

Dim entry As NotesViewEntry

Dim nav As NotesViewNavigator

Dim doc As NotesDocument

Dim i As Integer

Dim irow As Integer

Dim icol As Integer

Dim startrow As Integer

Dim dtotal As Double

Dim gtotal As Double

Set View = db.GetView( “Keywords” )

Dim viewdoc As NotesDocument

Set viewdoc = view.getdocumentbyKey(“Invoice Aging Template”)

Dim object As NotesEmbeddedObject

filenames = Evaluate(“@AttachmentNames”, viewdoc)

numberoffiles = Evaluate(“@Attachments”, viewdoc)

Set object = viewdoc.GetAttachment( filenames(0) )

localdrive = Environ$(“Temp”) & ""

Call object.ExtractFile(localdrive + filenames(0) )

Dim xlApp As Variant

Dim oworkbook As Variant

Set xlApp = CreateObject(“Excel.Application”)

xlApp.Visible = False

Set oworkbook = xlApp.Workbooks

oworkbook.Open(localdrive + filenames(0) )

xlApp.Sheets(“Invoice Aging”).Select

Set xlworksheet = xlApp.ActiveSheet

irow = 2

icol = 2

Set view = db.GetView(“(Report:Invoice Aging)”)

Set nav = view.CreateViewNav

Set entry = nav.GetFirst

startrow = irow

While Not(entry Is Nothing)

If entry.IsCategory Then 'new partner

If Not irow = startrow Then

With xlApp.cells(irow,icol+5)

.Font.Name = “Arial”

.Font.Size = 10

.Font.Bold = True

.Font.ColorIndex = 9

.HorizontalAlignment = -4152 'right

.Select

With xlApp.Selection.borders(8) '9=xlEdgeBottom, 7=xlEdgeLeft, 10=xlEdgeRight, 8=xlEdgeTop,

.LineStyle = -4119 '1 'xlDouble

.Weight = 4 'xlThick

.ColorIndex = -4105 'xlAutomatic

End With

End With

xlApp.cells(irow, icol+5) = “Total Outstanding”

With xlApp.cells(irow,icol+6)

.Font.Name = “Arial”

.Font.Size = 10

.Font.Bold = True

.Font.ColorIndex = 9

.HorizontalAlignment = -4152 'right

.Select

With xlApp.Selection.borders(8) '9=xlEdgeBottom, 7=xlEdgeLeft, 10=xlEdgeRight, 8=xlEdgeTop,

.LineStyle = -4119 '1 'xlDouble

.Weight = 4 'xlThick

.ColorIndex = -4105 'xlAutomatic

End With

End With

xlApp.cells(irow, icol+6) = dtotal

dtotal = 0

irow = irow + 2

xlApp.Range(“A2:H3”).Copy

xlApp.Range(“A” & Cstr(irow) & “:” & “H” & Cstr(irow)).Select

xlApp.ActiveSheet.Paste

xlApp.Application.CutCopyMode = False

End If

gtotal = gtotal + entry.ColumnValues(0)

dtotal = dtotal + entry.ColumnValues(0)

xlApp.cells(irow, icol) = entry.ColumnValues(1)

Else 'detail row

For i = 0 To 6

xlApp.cells(irow, icol+i) = entry.ColumnValues(i+2)

Next

End If

Subject: Still not sure how to write coding to export category

Will-There are several things here to cover and the final solution might be for your end-users to do something a bit different than you envision… at this time, see below:

Object variable not found means the code is trying to do something with something that doesn’t exist. You could enable debug and see exactly where (what line in the code) the error occurs. You could also (with debug on) walk line by line and see which objects have no properties as they are instantiated. The code snippet above doesn’t need to know the spreadsheet’s name however it does reference a specific worksheet “Invoice Aging” (if you don’t have this in your template just rem that line) … but all this might be unneeded when I read more about what you want to accomplish.

If I understand correctly, you don’t just want to send a view to excel, but you want to send certain records to excel. I suggest you have an agent that asks the user for the criteria NOT asking the user to twist open/close certain categories.

For example, the agent pops up a box and asks the user to enter something (month, department… or whatever) and then the agent goes and gets these records to export to excel.

-or-

If your criteria is more complicated than that, create a form which checkboxes, dialog lists… or whatever, that they complete then press a button that reads the form and then the agent goes and gets these records to export to excel.

When I say the agent goes and gets the records… I’m talking about creating a ‘collection’ via FTSearch (or if needed ViewSearch) then iterates through that collection as it populates the excel workbook.

Your interest in a categorized view can be because you aren’t sure how that would be done within LotusScript? You may be able to (under some circumstances) be able to get your collection already sorted as it’s created… but it’s also pretty simple to sort if not.

Once your data is sorted, you only need a ‘nested for’ to have categorize content as it’s routed to excel… LotusScript performs the calculations as it’s populating the spreadsheet.

Optionally, the collection could be copied to a hidden folder and the export runs against the folder which is categozied . You have plenty of options… and that is making your answer more difficult because more info is needed. I could send you a snippet that exports ‘selected documents’ to excel and it will work within any view… is that something you’d like?

Tell me what the report is to contain… for example, ‘1st Quarter’ Sales and/or ‘Past Due Accounts’ in the ‘Eastern Region’.

Subject: RE: Still not sure how to write coding to export category

or… use the NotesViewColumn class to walk the view and write to a file. We do this for our users… each web view has an “export” button that will export the content of the current view to their email in a csv file for easy opening in excel.

Subject: RE: Still not sure how to write coding to export category

Hi LotusNotes Guy-

“…or… use the NotesViewColumn class to walk the view and write to a file. We do this for our users… each web view has an “export” button that will export the content of the current view to their email in a csv file for easy opening in excel…”

I have several ways to do this for Notes Client users, but I’ve been stumped on providing this feature for the web. Would you send me that button code or post it as response?

:slight_smile: