vba 新建透视表sheet 判断版本

新建透视表sheet

Sheets.Add

ActiveSheet.Name = "PV_TB"


'判断透视表的版本号创建相应版本透视表

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:="数据透视表", DefaultVersion:=6

Case Is = "15.0" 'Excel2013

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

PRange.Address, VERSION:=xlPivotTableVersion15).CreatePivotTable _

TableDestination:="PV_TB!R3C1", TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion15

Case Is = "14.0" 'Excel2010

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

PRange.Address, VERSION:=xlPivotTableVersion14).CreatePivotTable _

TableDestination:="PV_TB!R3C1", TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion14

Case Is = "12.0" 'Excel2007

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

PRange.Address, VERSION:=xlPivotTableVersion12).CreatePivotTable _

TableDestination:="PV_TB!R3C1", TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion12

Case Is = "11.0" 'Excel2003

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _

PRange.Address, VERSION:=xlPivotTableVersion11).CreatePivotTable _

TableDestination:="PV_TB!R3C1", TableName:="数据透视表", DefaultVersion:=xlPivotTableVersion11

    End Select

你可能感兴趣的:(vba 新建透视表sheet 判断版本)