JackKaptijn
Registered User.
- Local time
- Today, 14:02
- Joined
- Dec 10, 2012
- Messages
- 38
I have a generic module for creating Excel reports.
This code works, but only once.....
When I close the Excel sheet and start it a second time, I get an error.
Error 1004, Methode Sheets of object _Global failed
It occurs at the end...at the line:
xlCht.SetSourceData Source:=Sheets("Table").Range("A3")
Anyone a suggestion?
Jack
This code works, but only once.....
Code:
Set rstBron = dbOFA.OpenRecordset("SELECT Year([Date]) AS Year, Cint(Format([Date],'mm')) AS Month, Amount FROM Invoices"
apXL.Visible = True
Set xlWsh = xlWbk.Worksheets(1)
xlWsh.Name = "Data"
xlWsh.Range("A1").Select
For Each fld In rstBron.Fields
apXL.ActiveCell = fld.Name
apXL.ActiveCell.Offset(0, 1).Select
Next fld
rstBron.MoveFirst
xlWsh.Range("A2").CopyFromRecordset rstBron
apXL.Sheets.Add
Set xlWsh = xlWbk.Worksheets(1)
xlWsh.Name = "Table"
xlWbk.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Data!A:C", Version:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:=xlWsh.Range("A3"), TableName:="Turnover", DefaultVersion _
:=xlPivotTableVersion12
With xlWsh.PivotTables("Turnover").PivotFields("Year")
.Orientation = xlColumnField
.Position = 1
End With
With xlWsh.PivotTables("Turnover").PivotFields("Maand")
.Orientation = xlRowField
.Position = 1
End With
xlWsh.PivotTables("Turnover").AddDataField xlWsh. _
PivotTables("Turnover").PivotFields("Amount"), "Sum of Amount", xlSum
Set xlCht = apXL.Charts.Add()
With xlCht
.Name = "Grafics"
End With
xlCht.SetSourceData Source:=Sheets("Table").Range("A3")xlWbk.ShowPivotTableFieldList = False
When I close the Excel sheet and start it a second time, I get an error.
Error 1004, Methode Sheets of object _Global failed
It occurs at the end...at the line:
xlCht.SetSourceData Source:=Sheets("Table").Range("A3")
Anyone a suggestion?
Jack