Solved

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

Posted on 2013-01-30
3
5,006 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

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 …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

749 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