I'm using excel/access 2007.
I've an Access file based on which I'd like to create a brand new Excel file with a pivot table.
So far I was able to create the file and the pivot table, but I'm unable to modify correctly the value of the pivot. It defaults to "Count of" while I'd like to have "Sum of".
I finally understood that the correct property to set is ".calculation", but, as it does for .orientation, access vba accepts only numbers.
Can anyone help me?
Thanks a lot
this is the code:
Set appexcel = CreateObject("Excel.Application")
Set wbk = appexcel.Workbooks.Add
wbk.ActiveSheet.Name = "PivotRes"
Set wks_pivot = wbk.worksheets("PivotRes")
wbk.sheets("Sheet2").Activate
wbk.ActiveSheet.Name = "PivotSrc"
Set wks_source = wbk.worksheets("PivotSrc")
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PivotDemand", 4)
With wks_source
.QueryTables.Add Connection:=rs, Destination:=.Range("A1")
.QueryTables(1).Refresh
End With
wbk.PivotCaches.Create(SourceType:=1, Sourcedata:="PivotSrc!R1C1:R5000C8", Version:=3).CreatePivotTable _
tabledestination:="PivotRes!R1C1", tableName:="PivotT", DefaultVersion:=3
wks_pivot.Activate
With wks_pivot.pivottables("PivotT").pivotfields("Customer_Name")
.Orientation = 1
End With
With wks_pivot.pivottables("PivotT").pivotfields("WaferQty")
.Orientation = 4
.calculation = 2 'not a sum
End With
I've an Access file based on which I'd like to create a brand new Excel file with a pivot table.
So far I was able to create the file and the pivot table, but I'm unable to modify correctly the value of the pivot. It defaults to "Count of" while I'd like to have "Sum of".
I finally understood that the correct property to set is ".calculation", but, as it does for .orientation, access vba accepts only numbers.
Can anyone help me?
Thanks a lot
this is the code:
Set appexcel = CreateObject("Excel.Application")
Set wbk = appexcel.Workbooks.Add
wbk.ActiveSheet.Name = "PivotRes"
Set wks_pivot = wbk.worksheets("PivotRes")
wbk.sheets("Sheet2").Activate
wbk.ActiveSheet.Name = "PivotSrc"
Set wks_source = wbk.worksheets("PivotSrc")
Set rs = CurrentDb.OpenRecordset("SELECT * FROM PivotDemand", 4)
With wks_source
.QueryTables.Add Connection:=rs, Destination:=.Range("A1")
.QueryTables(1).Refresh
End With
wbk.PivotCaches.Create(SourceType:=1, Sourcedata:="PivotSrc!R1C1:R5000C8", Version:=3).CreatePivotTable _
tabledestination:="PivotRes!R1C1", tableName:="PivotT", DefaultVersion:=3
wks_pivot.Activate
With wks_pivot.pivottables("PivotT").pivotfields("Customer_Name")
.Orientation = 1
End With
With wks_pivot.pivottables("PivotT").pivotfields("WaferQty")
.Orientation = 4
.calculation = 2 'not a sum
End With