Exporting only selected documents to excel

Hi All

I tried having selected 2 documents but it is trying to export all the documents in the view. The count which was highlighted comes correctly. Can yo please help?

Sub Initialize

    On Error Resume Next 

    Dim s  As New notessession 

    Dim uiw As New NotesUIWorkspace 

    Dim db As Notesdatabase 

    Dim uidoc As Notesuidocument 

    Dim othercol As Notesdocumentcollection 

    Dim agent As NotesAgent 

    Dim colmn As Integer 

    Dim row As Integer 

    Dim hcolmn As Integer 

    Dim otherdoc As Notesdocument 

    Dim otherview As NotesView 

    Dim resp As  Integer 

    'Dim currentviewname  As String 

    Dim uiv As NotesUIView 

    Set uiv = uiw.CurrentView 

    

    

    

    Set db =s.CurrentDatabase 

    Set othercol = db.UnprocessedDocuments 

    Msgbox othercol.Count 

    If othercol.Count=0 Then 

            Messagebox " No documents selected",16,"No documents selected" 

            Exit Sub 

    End If 

    

    If othercol.count  >= 1  Then 

            resp = Messagebox("Do you want to export only the selected"  & othercol.Count  &  "documents?" ,32, "Selected only?" ) 

    End If 

    

    For i=1 To othercol.Count 

            Set doc = othercol.GetNthDocument(i) 

            If doc.form(0)<>"frmRevResp" Then 

                    Msgbox "please select the Reviewee Form Documents only ",16,"error" 

                    Exit Sub 

            End If 

    Next 

    

    

    Dim object As NotesEmbeddedObject 

    Dim xlapp As Variant 

    Dim oworkbook As Variant 

    currentviewname = uiv.ViewName 

    Set otherview = db.GetView(currentviewname) 

    Set xlapp = createobject("Excel.application") 

    xlapp.visible = True 

    

    Set oworkbook = xlapp.workbooks 

    oworkbook.add 

    

    hcolmn = 1 

    Forall c In otherview.columns 

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

            hcolmn = hcolmn+1 

    End Forall 

    

    Row =2 

    If resp=6 Then 

            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  should be selected" 

                                            End 

                                    Else 

                                            Set otherdoc = otherview.GetNextDocument(otherdoc) 

                                    End If 

                            Else 

                                    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 

            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 

    

    xlapp.application.rows("1:1").select 

    With xlapp.application.selection.font 

            .bold = True 

            .colorindex = 48 

            .name = "arial" 

            .size = 12 

    End With 

    

    xlapp.applcation.rows("2:2").select 

    xlapp.application.activewindow.freezepanes = True 

    

    xlapp.cells.select 

    xlapp.selection.columns.autofit 

    xlapp.application.rows("1:1").select 

    

    xlapp.ActiveWorkbook.close 

    xlapp.application.quit 

    Close 

    xlapp.quit 

    Set xlapp = Nothing 

End Sub

Subject: Exporting only selected documents to excel

The problem is here: resp = Messagebox(“Do you want to export only the selected” & othercol.Count & “documents?” ,32, “Selected only?” )

Run this and see what you get for an answer:

Dim Resp As Integer



resp = Messagebox("Do you want to export only the selected documents?" ,32, "Selected only?" ) 

Messagebox resp

Then see where you use resp to make a decision.

HTH

Doug

Subject: RE: Exporting only selected documents to excel

Hi All

when i put this code in an agent it is working fine for me. Instead when i put the code in the script library and call from an agent, it is not showing the correct count of the unprocessed documents. why, what may be the error?

Subject: RE: Exporting only selected documents to excel

Thanks very much Doug, i believe that god has made you to respond in the right time.

It is working well now,praise the Lord.