Excel Set some colors for the table , For the viewing of tables , It's still good .
How to use it VBA Set the gradient on the table , This requires us to have a passion to master the method .
The following figure shows the effect of setting a gradient color , The color is not very good , But its function can be realized .
Let's explain in detail , adopt vba Code implementation method .
First of all, we should understand how to set the internal background of the table .
We need to know that the form uses Interior Object to represent , This means that some properties of the object are used .
Its simple solid color background as long as Color Attribute assignment can be used to set the background color .
for example ：
The code above is right A1 The background is set to red .
This property cannot be used when set to transition color , Other attributes .
So let's see interior Some properties of the object ：
The picture below is Pattern Enumeration type of constant , It's also fixed , Free to choose . Not much to explain .
What's really used is Gradient Attribute ColorStop object , Here's the picture ：
ColorStop A color code that represents a gradient fill in an area or selection , Its plural number ColorStop Specify all of the series **ColorStop** A collection of objects
Degree Represents the angle of the gradient .
In this way, you can achieve a gradient color within a cell 、 The angle has changed , Of course, there is also the light and shade and so on , Use other properties .
First set the angle and color .
Look at the following code diagram ：
Private Sub CommandButton1_Click()With Selection.Interior .Pattern = xlPatternLinearGradient' Specify as a linear gradient .Gradient.Degree = 45' Set gradient angle End WithWith Selection.Interior.Gradient.ColorStops.Add(1) .Color = RGB(211, 201, 1)' Color .TintAndShade = 0 ' Apply light colors and shadows End WithEnd Sub
Look at the code and you'll see , The internal setting of a table uses Interior object , Then set the linear gradient to use Pattern attribute , This constant is required xlPatternLinearGradient, If you choose something else, it's not a linear gradient , The following code is an error .
And then use Gradient.Degreeg To set the gradient angle 0-360 degree .
secondly , Here's another one ADD, Is to add a gradient color node , Gradient colors use ColorStop Object to set , This is equivalent to a color code .
This completes a cell gradient setting .
Is it a little dizzy , I don't understand . Because several different objects and properties are used here .
Interior Top of the object , Set properties .Pattern and .Gradient.Degree, Next, add a ColorStop object , Set up .Color and TintAndShade attribute .
There's no point in being simple , It's just to flip back and forth between so many objects and properties , We got a more boring result .
If you have very beautiful visual processing , So through this kind of operation , A beautiful form appears .
Welcome to collect 、 Focus on