更改 DataLabel 的 ColorIndex 的行为与文档所述不符
Changing the ColorIndex of a DataLabel is not behaving as stated by the documentation
我正在尝试更改 DataLabel 的颜色,但到目前为止我只能将颜色更改为红色或黑色。
我已尝试根据文档将 ColorIndex 设置为 "Values" 和 "Names":
https://docs.microsoft.com/en-us/office/vba/api/word.wdcolorindex
dim objChart as PowerPoint.Chart
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 0
此代码会将我的 DataLabel 更改为黑色,目前一切顺利。然而:
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 8
会将颜色更改为红色,就像大多数其他数字一样(我没有尝试过所有这些)。更好:
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = wdWhite
在调试模式下执行时会抛出 wdWhite
未定义的错误。如果立即打印 window ? wdWhite
它是空的,这解释了我使用 Option Explicit
时的错误。但是我很困惑它没有定义。
另外如果我让
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 0
然后立即打印 window 它将 return -1。
所以我有点困惑发生了什么。到目前为止,我还没有使用过 ColorIndex
但只使用过 Color.RGB
所以我不确定我是否做错了或做错了什么。
我可能必须包含一个特定的库吗?
也可能作为附加信息,我正在 Excel 中编写一个宏来填充 PowerPoint 中的图表。
感谢任何帮助。提前致谢:)
1) 我想你想要 Font.Color
而不是 ColorIndex
.
2) 您可以使用命名的 color constants,例如vbRed
、vbBlack
等
objChart.SeriesCollection(1).DataLabels(2).Font.Color = vbWhite
或者您可以根据需要使用 RGB
其他颜色:
objChart.SeriesCollection(1).DataLabels(2).Font.Color = RGB(100, 50, 0)
我正在尝试更改 DataLabel 的颜色,但到目前为止我只能将颜色更改为红色或黑色。
我已尝试根据文档将 ColorIndex 设置为 "Values" 和 "Names":
https://docs.microsoft.com/en-us/office/vba/api/word.wdcolorindex
dim objChart as PowerPoint.Chart
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 0
此代码会将我的 DataLabel 更改为黑色,目前一切顺利。然而:
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 8
会将颜色更改为红色,就像大多数其他数字一样(我没有尝试过所有这些)。更好:
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = wdWhite
在调试模式下执行时会抛出 wdWhite
未定义的错误。如果立即打印 window ? wdWhite
它是空的,这解释了我使用 Option Explicit
时的错误。但是我很困惑它没有定义。
另外如果我让
objChart.SeriesCollection(1).DataLabels(2).Font.ColorIndex = 0
然后立即打印 window 它将 return -1。
所以我有点困惑发生了什么。到目前为止,我还没有使用过 ColorIndex
但只使用过 Color.RGB
所以我不确定我是否做错了或做错了什么。
我可能必须包含一个特定的库吗? 也可能作为附加信息,我正在 Excel 中编写一个宏来填充 PowerPoint 中的图表。
感谢任何帮助。提前致谢:)
1) 我想你想要 Font.Color
而不是 ColorIndex
.
2) 您可以使用命名的 color constants,例如vbRed
、vbBlack
等
objChart.SeriesCollection(1).DataLabels(2).Font.Color = vbWhite
或者您可以根据需要使用 RGB
其他颜色:
objChart.SeriesCollection(1).DataLabels(2).Font.Color = RGB(100, 50, 0)