Solved

Using VBA to create a 3-gradient fill in a newly created shape.

Posted on 2013-01-30
3
4,918 Views
Last Modified: 2013-01-31
As we all know one of the more delightful improvements in Excel 2007 was removing the capability of recording shape formatting changes in VBA.  I'm looking for the simplest way possible to create a 3-gradient fill in a newly created shape.

Something that in effect says this, only with the proper terms and syntax

shp.select
shp.fill.gradientStop(1) = RGB(234,122,17)
shp.fill.gradientStop(1).stopPosition = 0%
shp.fill.gradientStop(2) = RGB(128,122,201)
shp.fill.gradientStop(2).stopPosition = 50%
shp.fill.gradientStop(3) = RGB(55,255,122)
shp.fill.gradientStop(3).stopPosition = 100%

shp.fill.gradientDirection = 90%

Given the fact that my terminology is probably all wrong, is it clear what I'm trying to accomplish?  :- )

Thanks,
John
0
Comment
Question by:gabrielPennyback
3 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 350 total points
ID: 38838524
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 150 total points
ID: 38838716
Perhaps something like
    Dim oFill As FillFormat
    Set oFill = ActiveSheet.Shapes(1).Fill
    With oFill
        .TwoColorGradient msoGradientHorizontal, 1
        With .GradientStops(1)
            .Color = RGB(234, 122, 17)
            .Position = 0
            .Transparency = 0
        End With
        With .GradientStops(2)
            .Color = RGB(55, 255, 122)
            .Position = 1
            .Transparency = 0
        End With
        .GradientStops.Insert RGB:=RGB(128, 122, 201), Position:=0.5, Transparency:=0
        .Visible = msoTrue
    End With

Open in new window

0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 38841117
Great answers, thanks. Rgonzo1971, I like yours because the breadcrumbs are so easy to follow. And Rory, I like yours because it gives me a different way of doing it that might be more useful in certain situations. Plus, it's great to hear from you again!

Thanks,
John
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Macro to change number to Month in Excel? 10 45
how to reset cell styles? 15 25
Transposing this formula ... 5 14
excel conditional formating 4 16
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question