修改柱形图中的底部图例

时间:2014-06-12 19:01:07

标签: excel charts excel-2010 legend

如图所示制作图例?

https://www.flickr.com/photos/101350199@N05/14406075674/

我使用文本框和形状来获取这些但是有没有办法让Excel自动执行?

1 个答案:

答案 0 :(得分:0)

我不想说,但我认为这是不可能的。 Excel以非常具体的方式对图形图例进行分组,我无法找到操作每个标签的方法。因此,它不能在VBA中作为宏记录或编码。我会发表评论,但我没有代表点。

我尝试使用宏录制器来制作像你提到的文本框和形状。这就是我得到的。尝试修改它。

Sub Macro6()

    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 338.25, 435, 62.25 _
    , 30.75).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Series 1"
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 8).ParagraphFormat. _
        FirstLineIndent = 0
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
        .Fill.ForeColor.TintAndShade = 0
        .Fill.ForeColor.Brightness = 0
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 11
        .Name = "+mn-lt"
    End With
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(7, 2).Font
        .BaselineOffset = 0
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
        .Fill.ForeColor.TintAndShade = 0
        .Fill.ForeColor.Brightness = 0
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 11
        .Name = "+mn-lt"
    End With
    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 433.5, 464.25, 67.5 _
        , 24).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Series 2"
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 8).ParagraphFormat. _
        FirstLineIndent = 0
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 6).Font
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
        .Fill.ForeColor.TintAndShade = 0
        .Fill.ForeColor.Brightness = 0
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 11
        .Name = "+mn-lt"
    End With
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(7, 2).Font
        .BaselineOffset = 0
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
        .Fill.ForeColor.TintAndShade = 0
        .Fill.ForeColor.Brightness = 0
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 11
        .Name = "+mn-lt"
    End With
    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 530.25, 435, 61.5, _
        24).Select
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Series 3"
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 8).ParagraphFormat. _
        FirstLineIndent = 0
    With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 8).Font
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1
        .Fill.ForeColor.TintAndShade = 0
        .Fill.ForeColor.Brightness = 0
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 11
        .Name = "+mn-lt"
    End With

    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 322.5, 435.75, 13.5, 15).Select
    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 416.25, 465, 15, 15.75).Select
    Selection.ShapeRange.ShapeStyle = msoShapeStylePreset10
    ActiveSheet.Shapes.AddShape(msoShapeRectangle, 513.75, 435, 14.25, 15.75).Select
    Selection.ShapeRange.ShapeStyle = msoShapeStylePreset11

End Sub