新建透視表sheet
Sheets.Add
ActiveSheet.Name = "PV_TB"
'判斷透視表的版本號(hào)創(chuàng)建相應(yīng)版本透視表
Select Case Application.VERSION
Case Is = "16.0" 'Excel2016
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
PRange.Address, VERSION:=6).CreatePivotTable _
TableDestination:="PV_TB!R3C1", TableName:="數(shù)據(jù)透視表", DefaultVersion:=6
Case Is = "15.0" 'Excel2013
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
PRange.Address, VERSION:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="PV_TB!R3C1", TableName:="數(shù)據(jù)透視表", DefaultVersion:=xlPivotTableVersion15
Case Is = "14.0" 'Excel2010
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
PRange.Address, VERSION:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="PV_TB!R3C1", TableName:="數(shù)據(jù)透視表", DefaultVersion:=xlPivotTableVersion14
Case Is = "12.0" 'Excel2007
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
PRange.Address, VERSION:=xlPivotTableVersion12).CreatePivotTable _
TableDestination:="PV_TB!R3C1", TableName:="數(shù)據(jù)透視表", DefaultVersion:=xlPivotTableVersion12
Case Is = "11.0" 'Excel2003
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
PRange.Address, VERSION:=xlPivotTableVersion11).CreatePivotTable _
TableDestination:="PV_TB!R3C1", TableName:="數(shù)據(jù)透視表", DefaultVersion:=xlPivotTableVersion11
? ? End Select