Dan*_*rth 7 powerpoint vba vsto office-interop powerpoint-vba
我试图在PowerPoint中更改直方图的图表标题的文本颜色.
这是我做的:
var colorFormat = chart.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor;
colorFormat.RGB = ...;
// or
colorFormat.ObjectThemeColor = ...;
Run Code Online (Sandbox Code Playgroud)
这适用于标准图表,如折线图.但它不适用于直方图,瀑布,树图等其他图表类型.
在这些情况下,设置ObjectThemeColor将文本设置为黑色.设置RGB实际上设置了正确的颜色.但是,在这两种情况下,只要用户更改选择,文本颜色就会跳回到之前的颜色.
如何设置其中一个图表标题的文字颜色?
我正在使用VSTO和C#,但VBA解决方案同样受欢迎,只要它可以转换为C#并仍然有效.
根据您提供的信息,我在 PowerPoint 中构建了直方图和瀑布图,并成功使用:
Sub ChartTitleFontColor()
Dim oShp As Shape
Dim oCht As Chart
'Waterfall on slide 1
Set oShp = ActivePresentation.Slides(1).Shapes(1)
If oShp.HasChart Then
Set oCht = oShp.Chart
End If
' Do stuff with your chart
If oCht.HasTitle Then
Debug.Print oCht.ChartTitle.Text
oCht.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(251, 5, 40)
End If
'Histogram on slide 2
Set oShp = ActivePresentation.Slides(2).Shapes(1)
If oShp.HasChart Then
Set oCht = oShp.Chart
End If
' Do stuff with your chart
If oCht.HasTitle Then Debug.Print oCht.ChartTitle.Text
oCht.ChartTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(251, 5, 40)
End If
' Clean up
Set oShp = Nothing
Set oCht = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)