Hallo,
ich habe folgenden Code, der auch in einem anderen View bei mir schon wunderbar funktioniert hat. Aber heute hab ich in einem anderen View angewendet und auch entsprechend angepasst, aber es bricht jetzt immer beim gleichen Datensatz ab...und ich weiss nicht warum. Es kommt die Meldung: OLE: Automation Error
Ich hoffe Ihr koennt mir helfen.
Viele Gruesse Chris
Code:
Sub Click(Source As Button)
Dim s As New NotesSession
Dim View As NotesView
Dim EC As NotesViewEntryCollection
Dim vE As NotesViewEntry
Dim n As Long
Dim Row As Long
Dim xlApp As Variant
Dim xlWB As Variant
Dim xlSheet As Variant
Dim column As NotesViewColumn
Dim i As Integer
On Error Goto Error_Export
Set View = s.CurrentDatabase.getView("Service Report \ by Model")
If Not(View Is Nothing) Then
Set xlApp = createobject("Excel.Application")
xlApp.StatusBar = "Create WorkSheet. Please wait."
xlApp.DisplayAlerts = False
xlApp.Visible = True
Set xlWB = xlApp.WorkBooks.Add
Set xlSheet = xlWB.Sheets(1)
xlSheet.Name = "MainData"
' write the columnnames
Row = 1
For i = 0 To view.ColumnCount -1
Set column = view.Columns(i)
xlSheet.Cells(Row, i +1) = column.ItemName
Next
' format the columnnames (grey and bold)
xlSheet.Range("A1:AW1").Interior.ColorIndex = 15
xlSheet.Range("A1:AW1").Font.Bold = True
' write the rows
Set EC = View.AllEntries
Set vE =EC.getFirstEntry
While Not(vE Is Nothing)
If vE.IsDocument Then
Row = Row + 1
' not the last row
For n = 0 To Ubound(vE.ColumnValues)
xlSheet.Cells(Row, n + 1) = vE.ColumnValues(n) ' to prevent excel errors
Next
xlApp.StatusBar = "Importing Notes Data"
End If
Set vE = EC.getNextEntry(vE)
Wend
End If
xlApp.Cells.Select
xlApp.Selection.Columns.AutoFit
xlApp.Selection.Rows.AutoFit
xlApp.Range("A1").Select
Call xlWB.SaveAs("C:\ServiceReportByModel.xls")
Call xlWB.Close
Call xlApp.Quit
Messagebox "Export successful to C:\ServiceReportByModel.xls!", 64, "Information"
Error_Export:
If (Err <> 0) Then
Messagebox Error$, 48, "An error has occurred..."
End If
Exit Sub
End Sub