Problem mit Export in Excel

  • Hab mein Script mal en bissel angepasst. Der funktioniert ohne Probleme. Ich bekomm die View "export" exportiert so wie sie auch in Notes steht.


    Nur leider bekomm ich alle Dokumente exportiert. Ich möchte aber nur die ausgewählten haben.


    Hab es mal mit "Set collection = db.UnprocessedDocuments" probiert und die "Set doc = view.GetFirstDocument" in Set doc = collection.GetFirstDocument" geändert aber bin da leider in eine Fehlermeldung (Variant does not contain a container) gelaufen.


    Habt ihr eine Idee was das sein könnte?


    danke





    Sub Initialize
    Dim xlApp As Variant
    Dim xlSheet As Variant
    Dim Session As New NotesSession
    Dim collection As NotesDocumentCollection
    Dim View As NotesView
    Dim doc As NotesDocument
    Dim db As NotesDatabase

    Dim xlCells As Variant ' Excel-Zelle
    Dim SpalteTitel As String
    Dim iSpalte, iZeile, iSpalteCount As Integer



    Set db = session.CurrentDatabase
    Set xlApp = CreateObject("Excel.application")

    xlApp.StatusBar = "WorkSheet wird erstellt. Bitte warten..."
    xlApp.Visible = True
    xlApp.Workbooks.Add
    xlApp.ReferenceStyle = 2

    Set xlCells = xlApp.ActiveWorkbook.ActiveSheet.Cells ' Excel-Zelle

    Set xlSheet = xlApp.Workbooks(1).Worksheets(1)
    xlsheet.Name = "Excel Druckvorlage"

    ' Ueberschriften

    With xlSheet
    .range("A1").Value = "Produkt"
    .range("B1").Value = "AFO"
    .range("C1").Value = "Beschreibung"
    .range("D1").Value = "Tool"
    .range("E1").Value = "Rezept"
    .range("F1").Value = "Name"
    .range("G1").Value = "Datum"

    End With

    ' Formatierung

    With xlapp
    .Columns("A:G").select
    .Rows("1:1").select
    .Selection.font.bold=True
    .Columns("A:A").Select
    .Selection.ColumnWidth = 30
    .Columns("B:B").Select
    .Selection.ColumnWidth = 25
    .Columns("C:C").Select
    .Selection.ColumnWidth = 50
    .Columns("D:D").Select
    .Selection.ColumnWidth = 25
    .Columns("E:E").Select
    .Selection.ColumnWidth = 25
    .Columns("F:F").Select
    .Selection.ColumnWidth = 20
    .Columns("G:G").Select
    .Selection.ColumnWidth = 20
    .Range("A1:G1").Select
    .Range("A1:G1").Activate
    .Selection.Borders(5).LineStyle = -4142
    .Selection.Borders(6).LineStyle = -4142
    .Selection.Borders(7).LineStyle = -4142
    .Selection.Borders(8).LineStyle = -4142
    .Selection.Borders(9).LineStyle = 1
    .Selection.Borders(9).Weight = -4138
    .Selection.Borders(9).ColorIndex = -4105
    .Selection.Borders(10).LineStyle = -4142
    .Selection.Borders(12).LineStyle = -4142
    End With

    iSpalte = 0
    iZeile = 1



    Set View = Session.CurrentDatabase.GetView("export")
    Set collection = db.UnprocessedDocuments

    ' titel exportieren
    Forall c In view.Columns
    iSpalte = iSpalte + 1
    SpalteTitel = c.title
    If SpalteTitel = "" Then
    SpalteTitel = "Spalte " + Cstr(iSpalte)
    End If
    xlCells( iZeile, iSpalte).Value = SpalteTitel
    End Forall

    ' einträge exportieren
    iSpalteCount = iSpalte
    Set doc = view.GetFirstDocument
    While Not doc Is Nothing
    iZeile = iZeile + 1
    For iSpalte = 1 To iSpalteCount
    xlCells(iZeile, iSpalte).Value = doc.ColumnValues(iSpalte - 1)
    Next
    Set doc = view.GetNextDocument(doc)
    Wend
    End Sub

  • code sieht so aus:
    rot ist die zeile mit dem fehler!


    Sub Initialize
    Dim xlApp As Variant
    Dim xlSheet As Variant
    Dim Session As New NotesSession
    Dim collection As NotesDocumentCollection
    Dim View As NotesView
    Dim doc As NotesDocument
    Dim db As NotesDatabase

    Dim xlCells As Variant ' Excel-Zelle
    Dim SpalteTitel As String
    Dim iSpalte, iZeile, iSpalteCount As Integer



    Set db = session.CurrentDatabase
    Set xlApp = CreateObject("Excel.application")

    xlApp.StatusBar = "WorkSheet wird erstellt. Bitte warten..."
    xlApp.Visible = True
    xlApp.Workbooks.Add
    xlApp.ReferenceStyle = 2

    Set xlCells = xlApp.ActiveWorkbook.ActiveSheet.Cells ' Excel-Zelle

    Set xlSheet = xlApp.Workbooks(1).Worksheets(1)
    xlsheet.Name = "Excel Druckvorlage"

    ' Ueberschriften

    With xlSheet
    .range("A1").Value = "Produkt"
    .range("B1").Value = "AFO"
    .range("C1").Value = "Beschreibung"
    .range("D1").Value = "Tool"
    .range("E1").Value = "Rezept"
    .range("F1").Value = "Name"
    .range("G1").Value = "Datum"

    End With

    ' Formatierung

    With xlapp
    .Columns("A:G").select
    .Rows("1:1").select
    .Selection.font.bold=True
    .Columns("A:A").Select
    .Selection.ColumnWidth = 30
    .Columns("B:B").Select
    .Selection.ColumnWidth = 25
    .Columns("C:C").Select
    .Selection.ColumnWidth = 50
    .Columns("D:D").Select
    .Selection.ColumnWidth = 25
    .Columns("E:E").Select
    .Selection.ColumnWidth = 25
    .Columns("F:F").Select
    .Selection.ColumnWidth = 20
    .Columns("G:G").Select
    .Selection.ColumnWidth = 20
    .Range("A1:G1").Select
    .Range("A1:G1").Activate
    .Selection.Borders(5).LineStyle = -4142
    .Selection.Borders(6).LineStyle = -4142
    .Selection.Borders(7).LineStyle = -4142
    .Selection.Borders(8).LineStyle = -4142
    .Selection.Borders(9).LineStyle = 1
    .Selection.Borders(9).Weight = -4138
    .Selection.Borders(9).ColorIndex = -4105
    .Selection.Borders(10).LineStyle = -4142
    .Selection.Borders(12).LineStyle = -4142
    End With

    iSpalte = 0
    iZeile = 1



    Set View = Session.CurrentDatabase.GetView("export")
    Set collection = db.UnprocessedDocuments

    ' Spaltentitel exportieren
    Forall c In view.Columns
    iSpalte = iSpalte + 1
    SpalteTitel = c.title
    If SpalteTitel = "" Then
    SpalteTitel = "Spalte " + Cstr(iSpalte)
    End If
    xlCells( iZeile, iSpalte).Value = SpalteTitel
    End Forall

    ' Ansichtseinträge exportieren
    iSpalteCount = iSpalte
    Set doc = collection.GetFirstDocument
    While Not doc Is Nothing
    iZeile = iZeile + 1
    For iSpalte = 1 To iSpalteCount
    [color=FF0000]xlCells(iZeile, iSpalte).Value = doc.ColumnValues(iSpalte - 1)[/color]
    Next
    Set doc = collection.GetNextDocument(doc)
    Wend
    End Sub

  • Es ist schon möglich nur mit einer anderen Technik


    Im Endeffekt sieht das dann so aus, daß du eine Schleife über alle Dokumente der View machst und über die Methode GetDocument der NotesDocumentCollection prüfst ob das Dokument in den UnprocessedDocuments ist

  • taurec dank dir schonmal für deine hilfe, weiß nur grad nicht so richtig wie ich das in angriff nehmen kann.
    wie mach ich den die abfrage in der schleife? müsste doch dann eine variable weitergeben oder?

  • Wenn du den folgenden Teil entsprechend abänderst geht es:



    Wichtig ist halt die If Bedingung

    • Offizieller Beitrag

    dann must Du über den NotesViewNavigator laufen.


    - aktuelle Kategorie merken
    -merken, ob schon ein Dokument der Kategorie exportiert wurde
    - - NEIN ... Kategorie rausschreiben
    - über NotesViewEntry die entsprechenden Spalten exportieren.


    Gruß
    Dirk

    Rein logisches Denken verschafft uns keine Erkenntnis über die wirkliche Welt.
    Alle Erkenntnis der Wirklichkeit beginnt mit der Erfahrung und endet mit ihr.
    Alle Aussagen, zu denen man auf rein logischen Wegen kommt, sind, was die Realität angeht, vollkommen leer.
    Albert Einstein

  • danke jungs für die vielen tollen tips!!


    ich hab das jetzt kurzfristig erstmal so gelöst, dass ich für die 10 Produkte jeweils eine eigene View erstellt hab und ich die dann komplett auslese.


    ich schau mir jetzt mal euere vorschläge an.


    dank euch schonmal