根据字体颜色更改单元格填充颜色
Change cell fill color based on font color
我需要将 Excel 2013 中的条件格式数据移动到 PowerPoint 2013 中预先存在的 table 中。字体颜色和格式将从 Excel 转移到 PowerPoint,但是需要手动添加单元格填充。
是否可以在 PowerPoint 中创建一个宏来搜索每个 table 的单元格,找到五种特定字体颜色“(xxx,xxx,xxx)”中的一种,然后用指定的颜色?
我在 Excel 中有 table 具有符合以下规则的条件格式颜色:
"Dark Green "
填充:(146、208、80)
字体颜色:(79, 98, 40)
"Light Green"
填充:(195、214、155)
字体颜色:(80, 98, 40)
"Grey"
填充:(242, 242, 242)
字体颜色:(166, 166, 166)
"Light Pink"
填充:(230、185、184)
字体颜色:(150, 55, 53)
"Dark Pink"
填充:(217、150、148)
字体颜色:(149, 55, 53)
我可以保留单元格字体和填充的一种方法是创建一个新图表,但是当需要完成将近一百次时,这会变得乏味。
理想情况下,我希望宏通过演示文稿进行搜索,如果它发现 table 单元格值的字体为(深绿色)(79、98、40),则将该单元格填充为(149, 208、80)。然后继续搜索接下来的四种颜色。
Option Explicit
Sub Tester()
Dim s As Slide, p As Presentation, shp As Shape
Dim rw As Row, cl As Cell
For Each s In ActivePresentation.Slides
For Each shp In s.Shapes
If shp.HasTable Then
For Each rw In shp.Table.Rows
For Each cl In rw.Cells
ProcessCellColors cl
Next cl
Next rw
End If
Next shp
Next s
End Sub
Sub ProcessCellColors(c As Cell)
Dim tf As TextFrame, clr As Long
Set tf = c.Shape.TextFrame
clr = -1
If tf.HasText Then
'assumes all text has the same color...
Select Case tf.TextRange.Font.Color.RGB
Case vbBlack: clr = vbYellow 'my testing
Case RGB(79, 98, 40): clr = RGB(146, 208, 80)
Case RGB(80, 98, 40): clr = RGB(195, 214, 155)
'....etc etc
End Select
If clr <> -1 Then
c.Shape.Fill.ForeColor.RGB = clr
End If
End If
End Sub
我需要将 Excel 2013 中的条件格式数据移动到 PowerPoint 2013 中预先存在的 table 中。字体颜色和格式将从 Excel 转移到 PowerPoint,但是需要手动添加单元格填充。
是否可以在 PowerPoint 中创建一个宏来搜索每个 table 的单元格,找到五种特定字体颜色“(xxx,xxx,xxx)”中的一种,然后用指定的颜色?
我在 Excel 中有 table 具有符合以下规则的条件格式颜色:
"Dark Green "
填充:(146、208、80) 字体颜色:(79, 98, 40)"Light Green"
填充:(195、214、155) 字体颜色:(80, 98, 40)"Grey"
填充:(242, 242, 242) 字体颜色:(166, 166, 166)"Light Pink"
填充:(230、185、184) 字体颜色:(150, 55, 53)"Dark Pink"
填充:(217、150、148) 字体颜色:(149, 55, 53)
我可以保留单元格字体和填充的一种方法是创建一个新图表,但是当需要完成将近一百次时,这会变得乏味。
理想情况下,我希望宏通过演示文稿进行搜索,如果它发现 table 单元格值的字体为(深绿色)(79、98、40),则将该单元格填充为(149, 208、80)。然后继续搜索接下来的四种颜色。
Option Explicit
Sub Tester()
Dim s As Slide, p As Presentation, shp As Shape
Dim rw As Row, cl As Cell
For Each s In ActivePresentation.Slides
For Each shp In s.Shapes
If shp.HasTable Then
For Each rw In shp.Table.Rows
For Each cl In rw.Cells
ProcessCellColors cl
Next cl
Next rw
End If
Next shp
Next s
End Sub
Sub ProcessCellColors(c As Cell)
Dim tf As TextFrame, clr As Long
Set tf = c.Shape.TextFrame
clr = -1
If tf.HasText Then
'assumes all text has the same color...
Select Case tf.TextRange.Font.Color.RGB
Case vbBlack: clr = vbYellow 'my testing
Case RGB(79, 98, 40): clr = RGB(146, 208, 80)
Case RGB(80, 98, 40): clr = RGB(195, 214, 155)
'....etc etc
End Select
If clr <> -1 Then
c.Shape.Fill.ForeColor.RGB = clr
End If
End If
End Sub