看來你將不得不遍歷圖表的屬性。一旦設置完畢,您可以使用VBE中的本地窗口查看cht
變量的其他屬性。這不是一個詳盡的選項列表,但它應該足以讓你開始!
Sub ReplaceTextInChart()
Dim cObj As ChartObject
Dim cht As Chart
Dim ax As Axis
Dim legEnt As LegendEntry
Dim srs As Series
Dim str As String 'this variable will use to hold the various text of the chart.'
Dim strSearch As String
Dim strReplace As String
strSearch = "s" '<-- test that I used, modify as needed.'
strReplace = "##" '<-- test that I used, modify as needed.'
For Each cObj In ActiveSheet.ChartObjects
Set cht = cObj.Chart
With cht
'## Check if the chart has a title, if so, do the replace.'
If .HasTitle Then
str = .ChartTitle.Characters.Text
.ChartTitle = Replace(.ChartTitle, strSearch, strReplace)
End If
'## Check if the chart has a legend, if so, do the replace'
If .HasLegend Then
For Each legEnt In .Legend.LegendEntries
str = legEnt.Format.TextFrame2.TextRange.Characters.Text
legEnt.Format.TextFrame2.TextRange.Characters.Text = _
Replace(str, strSearch, strReplace)
Next
End If
For Each ax In .Axes
'## Check if each Axis has a Title, if so, do the replace'
If ax.HasTitle Then
str = ax.AxisTitle.Characters.Text
ax.AxisTitle.Characters.Text = Replace(str, strSearch, strReplace)
End If
Next
'## For each series, do the replace in series.name'
For Each srs In .SeriesCollection
str = srs.Name
srs.Name = Replace(str, strSearch, strReplace)
Next
End With
Next
End Sub
我認爲兩者之間我們這將是非常有益的。 +1 – 2013-04-26 16:11:24