Public Sub ExportToExcel(strQuery As String, Optional strKoptekst As String = "", Optional blnRaw As Boolean = False)
Dim dbs As Database
Dim rst As Recordset
Dim appXL As Excel.Application
Dim wb As Workbook
Dim ws As Worksheet
Dim intRegel As Integer
Dim strOnderwerp As String
Dim intAantal As Integer
Set appXL = New Excel.Application
Set wb = appXL.Workbooks.Add
Set ws = wb.Worksheets(1)
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strQuery)
CreateSpreadsheetFromRS ws, rst, True, True
appXL.Visible = True 'for debugging purposes
If Not blnRaw Then
'Roteren 90 graden koptekst.
ws.Range("C1:I1").Select
With appXL.Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ws.Range("A1:I1").Select
With appXL.Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
With appXL 'Kolom breedten aanpassen
.Columns("C:E").Select
.Columns("C:E").EntireColumn.AutoFit
.Columns("I:I").ColumnWidth = 5.71
.Range("A1").Select
End With
ws.Range("A2").Select
appXL.ActiveWindow.FreezePanes = True
'Regel voor regel aflopen in de spreadsheet
'groeperen per process(onderwerp) beginnen op de tweede regel.
intRegel = 1
intAantal = 1
strOnderwerp = ws.Cells(intRegel, 1)
Do While True
If Len(ws.Cells(intRegel + intAantal, 1)) = 0 Then
Exit Do
End If
If strOnderwerp <> ws.Cells(intRegel + intAantal, 1) Then
FormatRptMgmt1 appXL, ws, intRegel, intRegel + intAantal - 1
intRegel = intRegel + intAantal
intAantal = 0
strOnderwerp = ws.Cells(intRegel, 1)
Else
If intAantal > 0 Then
ws.Cells(intRegel + intAantal, 1) = ""
End If
intAantal = intAantal + 1
End If
Loop
FormatRptMgmt1 appXL, ws, intRegel, intRegel + intAantal - 1
End If
If Len(strKoptekst) > 0 Then
AddHeader appXL, strKoptekst
End If
appXL.Visible = True
End Sub