我有一个宏似乎在Office 2010和Office 2016之间表现不同,特别是“组合图表”功能 . (我们处于Office 2010(Win7)和Office 2016(Win10)之间的过渡期 .
我想弄清楚的是如何在我们的宏中开发一个函数来“感知”用户是否在2010年或2016年打开宏(如果可能的话)并执行“创建图表”子
当我最初在2016年开发宏时,这是创建组合图的子 .
'' Create ComboChart (Excel2016only)
'
Range("A1:C11").Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("$A$1:$C$11")
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlLine
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlLineMarkersStacked
ActiveChart.FullSeriesCollection(2).AxisGroup = 2
当2010用户尝试运行它时,它将在.FullSeriesCollection(1).ChartType = xlColumnClustered“编译错误:找不到方法或数据成员” . 我相信它是因为组合图表直到2016年才出生 .
因此,我必须手动记录宏步骤,以确定如何在2010年做次要轴,因为它不是原生的 .
' ComboChartExcel2010 Macro
'
Range("A1:C11").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("Sheet1!$A$1:$C$11")
Application.WindowState = xlMaximized
ActiveChart.Legend.Select
ActiveChart.Legend.LegendEntries(2).Select
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).ChartType = xlLineMarkers
有什么建议来开发一个例程,它可以根据用户运行的Excel版本运行subs吗?现在我必须有一个UI框,要求用户选择他们正在运行的那个 .
2 回答
检查
Application.Version
将告诉您're/they'重新使用的Excel版本 .IF Application.Version = 15 Then
...您正在使用Excel 201312 = Excel 2007
14 = Excel 2010
15 = Excel 2013
16 = Excel 2016
这在Excel 2010中表现良好 .