How to add and apply gradients to shapes with VBA?

That's why this tutorial shows where it can be configured and then applied to a module added to an Excel sheet.

Add a figure in the Excel sheet

If you have come to this guide to learn how to apply gradients to shapes, it means that you have the knowledge to add figures.

But it never hurts to mention how to do it for those who are inexperienced with Excel and the tools at its disposal.



It may be that for an educational job you have been asked to perform this function and therefore you have to learn how to add shapes and apply the degrading effect.


So, the first thing to do and which is obvious is to open a new spreadsheet by entering from the program icon.

This way, you keep selecting the blank option and a new Excel template will be generated. Subsequently, the action is directed towards the board " Inserisci ".

In it you will see a button with the name of " Illustrations ”In which three alternatives to choose relative to the segment will appear.

How to add and apply gradients to shapes with VBA?

Among these, there will be one called " Figures “, Which will have a small arrow pointing downwards.

This " Arrow “, When selected, will show a wide range of figures classified into different categories, such as geometric figures and others.

You can choose, for example, the shape of the cube. This will cause the drawing tool to be enabled, which will be used by clicking anywhere and holding down strokes for resize the shape.

Another way to add shapes to your spreadsheet is to use the AddShape method.



When you determine what size you want it to be, you just need to solar and the image will be inserted into the Excel sheet.


Apply shades to shapes inserted in the Excel sheet

Now, to apply gradients to shapes inserted in the Excel sheet, you need to use a tool called " Visual Basic ".

This is a type of console where commands are added, also known as " Macro “, To build an extra function. VBA allows you to quickly and easily create macros for use in Excel.

It can be accessed via the " Developer "Or" Programmer ”Where the aforementioned tool will be at the top left.

When you click on it, a pop-up window will open consisting of a location sidebar and a blank screen in the rest.

To proceed, you can create a new folder and then a new location called " Forms "Or" Macro ”Where the gradient effect will be inserted.

Next, the command line will be written in the empty section that will enable the desired function in question.

How to add and apply gradients to shapes with VBA?

The programming of this macro is based on three arguments, which will determine the parameters, which are: " Style "," Variant " is " Filling ". It would look like this:

Sub GradiantShape


Dim obFill as FillFormat

Imposta obFill = ActiveSheet.Shapes (1).Fill

ObFill.ForceColor.RGB = RGB (255, 255, 255)

Which obFill

.OneColorGradient msoGradientVertical, 2, 0.02

Which GradientStops (1)


.Color = RGB (234, 122, 17)

.Position = 0

.Transparency = 0

End that

It should be noted that this can vary, it will all depend on the style or the way the user wants the effect to be seen.


The same thing happens with colors, the values ​​presented in brackets represent the tone that the figure will have, which can be changed at will.


It should be noted that this formula would be something standard, there are many combinations, but the ideal is to take a course to specialize in building one.

Another important fact is that the formula is not copied and pasted, each word must be typed step by step so that Excel on drive and there are no mistakes.

Just as the VBA format allows you to create macros for working with shapes with this program, you can also create macros to add graphics to your Excel sheets, both regular and pie charts.

add a comment of How to add and apply gradients to shapes with VBA?
Comment sent successfully! We will review it in the next few hours.