Consulting

Results 1 to 3 of 3

Thread: Set gradient fill across a group

  1. #1

    Question Set gradient fill across a group

    Hi

    In the PPT interface, if I group a selection of shapes, lets say three filled circled in a line and then set the Fill for the group to be gradient - say dark blue on the left fading to light blue on the right - then the gradient spans the circles. The left one is mostly dark, the right is mostly light, the middle one is in between.

    I have code that can apply a specific gradient design to a shape. It works fine for individual shapes.

    If I apply that to a shape that is a group I would expect to see the same as described above. Unfortunately I don't, what I get is each shape in my group shaded to the gradient, so for the example above, each circle is dark blue on the left and light blue on the right.

    Does anyone know how to set the gradient across the shapes using VBA, the same as the interface can do?

    Here is my code ... modified a bit as is client bespoke ...

    It assumes you have a single shape (which might be a group) selected before it runs ...

    Public Sub TestGradExample()
    
    
        Dim shpTgt  As Shape
        Dim iStyle          As Integer
        Dim iVariant        As Integer
        Dim iAngle          As Integer
        
        Set shpTgt = ActiveWindow.Selection.ShapeRange(1)
        
        With shpTgt.Fill
            
            iStyle = 2 'these are fetched based on choice user makes really but these values are valid for this test
            iVariant = 1
            iAngle = 0
            
            'get a gradient going
            .OneColorGradient iStyle, iVariant, iAngle
            
            'Modify it (this is done as a loop in the real code but equates to this)
            
            .GradientStops(1).Color.RGB = RGB(255, 0, 0)
            .GradientStops(1).Position = 0
            .GradientStops(1).Transparency = 0
            
            .GradientStops.Insert RGB(0, 255, 0), 0.5, 0
            .GradientStops.Insert RGB(0, 0, 255), 1, 0
            
            
        End With
    
    
        Set shpTgt = Nothing
        
    End Sub
    If I run that on one shape I get red on the left, lots of green and blue on the right

    If I run it against a group of two or more shapes next to each other, each shape gets the above not a gradient across them all.

    Thanks

    Simon

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I have never had success trying to do this with a group. However you will probably find it works with a combined shape. Obviously combined shapes act differently to groups so it depends what you need whether this would work for you.

    The code for combining shapes is simple but it doesn't seem to return the new shape making it tricky!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Hi John

    Thanks for that. Reassuring to know my analysis of the object model wasn't missing something.

    Not sure combining into a single image will work for me given the user creates the sequence of objects on the fly via a different interface but I may explore it as it could be an option, provided they accept it can't be reversed!

    Simon

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •