更改整张纸的背景颜色

时间:2022-12-24 21:16:46

Is there a way to change the Background color into xlNone, for example to the entire sheet. I see that you can put a background image... But how can you change the color for all cells in the sheet?

有没有办法将背景颜色更改为xlNone,例如更改为整个工作表。我看到你可以放一张背景图片......但你怎么能改变表格中所有单元格的颜色呢?

3 个解决方案

#1


14  

You can do this quite easy with this code:

使用此代码,您可以轻松完成此操作:

Public Sub Demo()
  'set color
  WorksheetName.Cells.Interior.ColorIndex = 1 'black
  'clear color
  WorksheetName.Cells.Interior.ColorIndex = xlColorIndexNone
end sub

Or if you don't need VBA, just click at this little icon in the corner:

或者如果您不需要VBA,只需点击角落里的这个小图标:

更改整张纸的背景颜色

and select a color, or to use no color - using right click menu or ribbon menu.

并选择一种颜色,或使用无颜色 - 使用右键菜单或功能区菜单。

Just because of the other answers, I want to remind - it is not necessary to use selections! This is bad macro-recorder style. There are only few occations, where using selections is necessary or a good idea. You can always just use a specific range.

仅仅因为其他答案,我想提醒一下 - 没有必要使用选择!这是糟糕的宏录音机风格。只有少数几个位置,使用选择是必要的或一个好主意。您始终可以使用特定范围。

#2


2  

Try this

尝试这个

Sheets("Sheet1").Select    
Cells.Select
With Selection.Interior
    .Pattern = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With

#3


2  

Here is how you can change the background color for all cells in the current sheet

以下是如何更改当前工作表中所有单元格的背景颜色

 Cells.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.14996795556505   'grey color
        .PatternTintAndShade = 0
    End With

#1


14  

You can do this quite easy with this code:

使用此代码,您可以轻松完成此操作:

Public Sub Demo()
  'set color
  WorksheetName.Cells.Interior.ColorIndex = 1 'black
  'clear color
  WorksheetName.Cells.Interior.ColorIndex = xlColorIndexNone
end sub

Or if you don't need VBA, just click at this little icon in the corner:

或者如果您不需要VBA,只需点击角落里的这个小图标:

更改整张纸的背景颜色

and select a color, or to use no color - using right click menu or ribbon menu.

并选择一种颜色,或使用无颜色 - 使用右键菜单或功能区菜单。

Just because of the other answers, I want to remind - it is not necessary to use selections! This is bad macro-recorder style. There are only few occations, where using selections is necessary or a good idea. You can always just use a specific range.

仅仅因为其他答案,我想提醒一下 - 没有必要使用选择!这是糟糕的宏录音机风格。只有少数几个位置,使用选择是必要的或一个好主意。您始终可以使用特定范围。

#2


2  

Try this

尝试这个

Sheets("Sheet1").Select    
Cells.Select
With Selection.Interior
    .Pattern = xlNone
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With

#3


2  

Here is how you can change the background color for all cells in the current sheet

以下是如何更改当前工作表中所有单元格的背景颜色

 Cells.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.14996795556505   'grey color
        .PatternTintAndShade = 0
    End With