將指定的元素新增至圖表或圖表上選取的物件。
語法
expression。
SetElement
(RHS)
expression 代表 Chart 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| RHS | 必要 | MsoChartElementType | 圖表元素類型要新增的其中一個列舉常數。 |
傳回值
Nothing
註解
SetElement 方法的 RHS 值對應至 [新增圖表元素] 子功能表中的項目。 會根據圖表類型啟用不同的項目。 如果您嘗試新增特定圖表中不存在的元素,您會收到不明的錯誤。 例如,在 3D 圖表上,[新增圖表元素] 下拉式清單中的 [誤差線] 項目是無法使用的。 呼叫 Chart.SetElement msoElementErrorBarStandardDeviation 導致錯誤。
範例
下列範例會將次要格線新增至數值軸,並將資料標籤圖說文字新增至第二個資料數列。
Sub TestSetElements()
Dim chartShape As Shape
Dim reportName As String
reportName = "Simple 3D chart"
Set chartShape = ActiveProject.Reports(reportName).Shapes(1)
With chartShape.Chart
.SetElement msoElementChartTitleAboveChart
' Select the major gridlines on the value axis, and then add minor gridlines.
.axes(Office.xlValue).MajorGridlines.Select
.SetElement msoElementPrimaryCategoryGridLinesMinor
' Select the second data series and add data label callouts.
If .SeriesCollection.Count > 1 Then
.SeriesCollection(2).Select
.SetElement msoElementDataLabelCallout
End If
End With
End Sub
另請參閱
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。