代表工作簿中的图表。
注解
图表可以是内嵌图表(嵌入 ChartObject 对象中),也可以是单独的图表工作表。
Charts 集合包含工作簿中每个图表工作表的 Chart 对象。 Charts(index)(其中 index 是图表工作表索引号或名称)可用于返回一个 Chart 对象。
图表 index 号表示图表工作表在工作簿标签栏上的位置。 Charts(1) 是工作簿中的第一个(最左侧)图表,Charts(Charts.Count) 是最后一个(最右侧)图表。
所有图表工作表都计入索引计数,即使处于隐藏状态,也不例外。 图表工作表名称显示在图表的工作簿标签上。 使用 ChartObject 对象的 Name 属性设置或返回图表名称。
下面的示例在图表工作表 1 中更改系列 1 的颜色。
Charts(1).SeriesCollection(1).Format.Fill.ForeColor.RGB = rgbRed
下面的示例将名为“Sales”的图表移到活动工作簿的末尾。
Charts("Sales").Move after:=Sheets(Sheets.Count)
Chart 对象也是 Sheets 集合的成员。此集合包含工作簿中的所有工作表(图表工作表和工作表)。 Sheets(index)(其中 index 是工作表索引号或名称)可用于返回一个表。
如果图表是活动对象,可以使用 ActiveChart 属性引用它。 如果用户已选择图表工作表,或已使用 Chart 对象的 Activate 方法或 ChartObject 对象的 Activate 方法激活了图表工作表,图表工作表就是活动对象。
下面的示例激活图表工作表 1,并设置图表类型和标题。
Charts(1).Activate
With ActiveChart
.Type = xlLine
.HasTitle = True
.ChartTitle.Text = "January Sales"
End With
如果用户已选择内嵌图表,或已使用 Activate 方法激活内嵌图表中包含的 ChartObject 对象,内嵌图表就是活动对象。
下面的示例激活工作表 1 中的内嵌图表 1,并设置图表类型和标题。 请注意,在激活内嵌图表后,此示例中的代码与上一示例相同。 使用 ActiveChart 属性,可以写入 Visual Basic 代码,从而引用内嵌图表或图表工作表(以活动对象为准)。
Worksheets(1).ChartObjects(1).Activate
ActiveChart.ChartType = xlLine
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "January Sales"
如果图表工作表是活动工作表,可以使用 ActiveSheet 属性引用它。 下面的示例使用 Activate 方法激活名为 Chart1 的图表工作表,并将图表中系列 1 的内部颜色设置为蓝色。
Charts("chart1").Activate
ActiveSheet.SeriesCollection(1).Format.Fill.ForeColor.RGB = rgbBlue
事件
- Activate
- BeforeDoubleClick
- BeforeRightClick
- Calculate
- Deactivate
- MouseDown
- MouseMove
- MouseUp
- Resize
- Select
- SeriesChange
方法
- Activate
- ApplyChartTemplate
- ApplyDataLabels
- ApplyLayout
- Axes
- ChartGroups
- ChartObjects
- ChartWizard
- CheckSpelling
- ClearToMatchColorStyle
- ClearToMatchStyle
- Copy
- CopyPicture
- 删除
- Evaluate
- Export
- ExportAsFixedFormat
- FullSeriesCollection
- GetChartElement
- Location
- Move
- OLEObjects
- Paste
- PrintOut
- PrintPreview
- Protect
- Refresh
- SaveAs
- SaveChartTemplate
- Select
- SeriesCollection
- SetBackgroundPicture
- SetDefaultChart
- SetElement
- SetSourceData
- Unprotect
属性
- 应用程序
- AutoScaling
- BackWall
- BarShape
- CategoryLabelLevel
- ChartArea
- ChartColor
- ChartStyle
- ChartTitle
- ChartType
- CodeName
- Creator
- DataTable
- DepthPercent
- DisplayBlanksAs
- Elevation
- Floor
- GapDepth
- HasAxis
- HasDataTable
- HasLegend
- HasTitle
- HeightPercent
- Hyperlinks
- 索引
- Legend
- MailEnvelope
- 名称
- Next
- PageSetup
- Parent
- Perspective
- PivotLayout
- PlotArea
- PlotBy
- PlotVisibleOnly
- Previous
- PrintedCommentPages
- ProtectContents
- ProtectData
- ProtectDrawingObjects
- ProtectFormatting
- ProtectionMode
- ProtectSelection
- RightAngleAxes
- Rotation
- SeriesNameLevel
- Shapes
- ShowAllFieldButtons
- ShowAxisFieldButtons
- ShowDataLabelsOverMaximum
- ShowExpandCollapseEntireFieldButtons
- ShowLegendFieldButtons
- ShowReportFilterFieldButtons
- ShowValueFieldButtons
- SideWall
- Tab
- Visible
- Walls
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。