如何更改单元格内容的背景色?

问题描述 投票:0回答:1

我编写了一些代码,它将更改单元格的背景颜色,但我只想更改单元格内容的颜色。

我试图寻找正确的代码,但无法用我的代码修复它。

Sub cellColor()
    Dim colCount As Integer
    Dim count As Integer

    colCount = Selection.Tables(1).Columns.count
    col = 0

    If Selection.Shading.BackgroundPatternColor = RGB(255, 255, 255) Then
        While col < colCount
            Selection.Shading.BackgroundPatternColor = RGB(255, 114, 86)
            col = col + 1
        Wend
    Else
        Selection.Shading.BackgroundPatternColor = RGB(255, 255, 255)
    End If
    Exit Sub
End Sub
vba word-vba word
1个回答
1
投票

您需要使用单元格范围的Shading,而不是Selection范围。

这应该起作用:

Selection.Cells(1).Range.Font.Shading.BackgroundPatternColor = RGB(255, 114, 86)
© www.soinside.com 2019 - 2024. All rights reserved.