Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel';s ColorIndex VBA转换为HTML颜色_Html_Excel_Vba_Charts_Colors - Fatal编程技术网

Excel';s ColorIndex VBA转换为HTML颜色

Excel';s ColorIndex VBA转换为HTML颜色,html,excel,vba,charts,colors,Html,Excel,Vba,Charts,Colors,我有一个工作代码,可以根据条件格式单元格颜色更改图表颜色 唯一的问题是,当它将颜色应用于图表时,它采用ColorIndex属性,该属性仅限于Excels 56调色板。我的图表看起来像是孩子们的生日聚会,不像十亿RGB的颜色那样优雅 是否有办法提取RGB颜色代码并将其应用于图表?我可以手动做任何颜色的我想要的,但我希望它是全自动的 Sub ColorChartColumnsbyCellColor() Dim xChart As Chart Dim I As Long, xRows As Long

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

唯一的问题是,当它将颜色应用于图表时,它采用ColorIndex属性,该属性仅限于Excels 56调色板。我的图表看起来像是孩子们的生日聚会,不像十亿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
替换此行:

.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
替换此行:

.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

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