Solved

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

Posted on 2013-01-30
3
4,671 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 48

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now