Excel table how to set gradient color, VBA programming advanced learning, in-depth explanation
Refreshing 2020-11-26 23:40:02

No.1


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 .

Excel How to set the gradient of the table ,vba Advanced learning in programming , In depth explanation

No.2


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 :

Range(“A”).interior.color=rgb(222,1,1)

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 :

Excel How to set the gradient of the table ,vba Advanced learning in programming , In depth explanation


The picture below is Pattern Enumeration type of constant , It's also fixed , Free to choose . Not much to explain .

Excel How to set the gradient of the table ,vba Advanced learning in programming , In depth explanation


What's really used is Gradient Attribute ColorStop object , Here's the picture :

Excel How to set the gradient of the table ,vba Advanced learning in programming , In depth explanation


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 :

Excel How to set the gradient of the table ,vba Advanced learning in programming , In depth explanation

No.3


Code
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 .

---END---

Welcome to collect 、 Focus on
版权声明
本文为[Refreshing]所创,转载请带上原文链接,感谢
https://fheadline.com/2020/11/20201126233957902x.html
相似文章

2021-08-09