一段自己录制的Excel宏代码(画柏拉图)

  Sub Macro2()
'
'
Macro2 Macro
'
宏由 grace 录制,时间: 2007-7-4
'

'
    Charts.Add
    ActiveChart.ApplyCustomType ChartType:
= xlBuiltIn, TypeName : = " 线-柱图 "
    ActiveChart.SetSourceData Source:
= Sheets( " Sheet2 " ).Range( " I26 " )
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(
1 ).XValues = " =Sheet2!R3C1:R10C1 "
    ActiveChart.SeriesCollection(
1 ).Values = " =Sheet2!R3C3:R10C3 "
    ActiveChart.SeriesCollection(
2 ).Values = " =Sheet2!R2C4:R10C4 "
    ActiveChart.SeriesCollection(
2 ).AxisGroup = 2   'Excel自动生成的宏代码中没有这一行,执行时会出现“方法Axes作用于对象_Chart时失败”的错误信息。加上这一句就可以了
    ActiveChart.Location Where:
= xlLocationAsObject, Name: = " Sheet2 "
   
With ActiveChart
        .HasTitle
= True
        .ChartTitle.Characters.Text
= " plato "
        .Axes(xlCategory, xlPrimary).HasTitle
= False
        .Axes(xlValue, xlPrimary).HasTitle
= False
        .Axes(xlCategory, xlSecondary).HasTitle
= False
        .Axes(xlValue, xlSecondary).HasTitle
= False
   
End With
   
With ActiveChart
        .HasAxis(xlCategory, xlPrimary)
= True
        .HasAxis(xlCategory, xlSecondary)
= True
        .HasAxis(xlValue, xlPrimary)
= True
        .HasAxis(xlValue, xlSecondary)
= True
   
End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType
= xlCategoryScale
    ActiveChart.Axes(xlCategory, xlSecondary).CategoryType
= xlCategoryScale
    ActiveChart.HasDataTable
= False
    ActiveChart.SeriesCollection(
1 ).Select
    ActiveChart.SeriesCollection(
1 ).ChartType = xlColumnClustered
    ActiveChart.SeriesCollection(
1 ).Select
    ActiveChart.SeriesCollection(
1 ).ApplyDataLabels AutoText: = True , LegendKey: = _
       
False , ShowSeriesName: = False , ShowCategoryName: = False , ShowValue: = True , _
        ShowPercentage:
= False , ShowBubbleSize: = False
   
With ActiveChart.ChartGroups( 1 )
        .Overlap
= 0
        .GapWidth
= 0
        .HasSeriesLines
= False
        .VaryByCategories
= True
   
End With
    ActiveChart.Axes(xlValue).Select
   
With ActiveChart.Axes(xlValue)
        .MinimumScaleIsAuto
= True
        .MaximumScale
= 1
        .MinorUnitIsAuto
= True
        .MajorUnitIsAuto
= True
        .Crosses
= xlAutomatic
        .ReversePlotOrder
= False
        .ScaleType
= xlLinear
        .DisplayUnit
= xlNone
   
End With
    ActiveChart.Axes(xlValue, xlSecondary).Select
   
With ActiveChart.Axes(xlValue, xlSecondary)
        .MinimumScaleIsAuto
= True
        .MaximumScale
= 1
        .MinorUnitIsAuto
= True
        .MajorUnitIsAuto
= True
        .Crosses
= xlMaximum
        .ReversePlotOrder
= False
        .ScaleType
= xlLinear
        .DisplayUnit
= xlNone
   
End With
    ActiveChart.Axes(xlCategory, xlSecondary).Select
   
With Selection.Border
        .Weight
= xlHairline
        .LineStyle
= xlAutomatic
   
End With
   
With Selection
        .MajorTickMark
= xlInside
        .MinorTickMark
= xlNone
        .TickLabelPosition
= xlNone
   
End With
   
With ActiveChart.Axes(xlCategory, xlSecondary)
        .Crosses
= xlMaximum
        .TickLabelSpacing
= 1
        .TickMarkSpacing
= 1
        .AxisBetweenCategories
= False
        .ReversePlotOrder
= False
   
End With
    ActiveChart.SeriesCollection(
2 ).Select
    ActiveChart.SeriesCollection(
2 ).ChartType = xlLineMarkers
    ActiveChart.SeriesCollection(
2 ).Select
   
With ActiveChart.ChartGroups( 2 )
        .HasDropLines
= False
        .HasHiLoLines
= False
        .HasUpDownBars
= False
        .VaryByCategories
= True
   
End With
    ActiveChart.Axes(xlCategory, xlSecondary).Select
   
With Selection.Border
        .Weight
= xlHairline
        .LineStyle
= xlAutomatic
   
End With
   
With Selection
        .MajorTickMark
= xlInside
        .MinorTickMark
= xlNone
        .TickLabelPosition
= xlNone
   
End With
    ActiveChart.ChartArea.Select
End Sub

你可能感兴趣的:(.NET)