【问题标题】:Excel's ColorIndex VBA convert to HTML colorsExcel 的 ColorIndex VBA 转换为 HTML 颜色
【发布时间】:2019-12-25 16:33:09
【问题描述】:

我有工作代码可以根据条件格式单元格颜色更改图表颜色。

唯一的问题是,当它将颜色应用于图表时,它采用了仅限于 Excels 56 调色板的 ColorIndex 属性。然后我的图表看起来像一个孩子的生日派对,看起来不像十亿 RGB 颜色那么优雅。

有没有办法提取 RGB 颜色代码并将其应用于图表?我可以手动设置任何我想要的颜色,但我希望它全部自动化。

Sub ColorChartColumnsbyCellColor()

Dim xChart As Chart
Dim I As Long, xRows As Long
Dim xRg As Range, xCell As Range
On Error Resume Next
Set xChart = ActiveSheet.ChartObjects("Chart 2").Chart
If xChart Is Nothing Then Exit Sub

With xChart.SeriesCollection(1)
    Set xRg = ActiveSheet.Range(Split(Split(.Formula, ",")(1), "!")(1))
    xRows = xRg.Rows.Count
    Set xRg = xRg(1)
    For I = 1 To xRows
        .Points(I).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(xRg.Offset(I - 1, 4).DisplayFormat.Interior.ColorIndex)
    Next
End With
End Sub

【问题讨论】:

  • Interior.ColorIndex > RGB 有可能吗?
  • 直接使用xRg.Offset(I - 1, 4).DisplayFormat.Interior.Color
  • 当我使用它时 ^^ 我得到一个运行时错误:“方法'对象的颜色'_Workbook”失败我做错了什么?
  • 删除颜色部分。只是:.Points(I).Format.Fill.ForeColor.RGB = xRg.Offset(I - 1, 4).DisplayFormat.Interior.Color
  • DUUUDEEE 你帮了我很多忙。这里有评分系统吗,可以给你打个星吗?

标签: html excel vba charts colors


【解决方案1】:

替换这一行:

.Points(I).Format.Fill.ForeColor.RGB = ThisWorkbook.Colors(xRg.Offset(I - 1, 4).DisplayFormat.Interior.ColorIndex)

用这个:

.Points(I).Format.Fill.ForeColor.RGB = xRg.Offset(I - 1, 4).DisplayFormat.Interior.Color

【讨论】:

    猜你喜欢
    • 2019-01-05
    • 2017-05-22
    • 1970-01-01
    • 2012-07-07
    • 2018-06-17
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多