Share via

VBA Code to Set Line Gradient?

Anonymous
2011-01-12T15:08:34+00:00

I can manually set an object's line color in PowerPoint to have a gradient "fill" and varying transparency, just as I can for the object's fill.  However, I can't figure out how to do that using VBA.  I have the code for the fill working fine, but I'm not sure what object to access to set the line to use a gradient.  Since Microsoft kindly removed recording capability, there is no easy way to get an example.

Can someone provide me the basics of setting a line to have a gradient?

Fill example that sets a gradient fill with varying transparency:

        Set GradientShapeFill = theShape.Fill

        With GradientShapeFill

                .ForeColor.RGB = RGB(0, 128, 128)

                .OneColorGradient msoGradientVertical, 1, 1

                scaleHSL.Hue = tHSL.Hue

                scaleHSL.Saturation = myMin(tHSL.Saturation, 0.99999)

                scaleHSL.Luminance = tHSL.Luminance * 0.7

                tRGB = HSLtoRGB(scaleHSL)

                .GradientStops.insert RGB(tRGB.Red, tRGB.Green, tRGB.Blue), 0#

                scaleHSL.Hue = tHSL.Hue

                scaleHSL.Saturation = myMin(tHSL.Saturation, 0.99999)

                scaleHSL.Luminance = tHSL.Luminance * 0.85

                tRGB = HSLtoRGB(scaleHSL)

                .GradientStops.insert RGB(tRGB.Red, tRGB.Green, tRGB.Blue), 0.5

                scaleHSL.Hue = tHSL.Hue

                scaleHSL.Saturation = myMin(tHSL.Saturation, 0.99999)

                scaleHSL.Luminance = tHSL.Luminance

                tRGB = HSLtoRGB(scaleHSL)

                .GradientStops.insert RGB(tRGB.Red, tRGB.Green, tRGB.Blue), 1#

                .GradientStops.Delete 2

                .GradientStops.Delete 1

                .GradientStops(1).Transparency = 1#

                .GradientStops(2).Transparency = 0.33

                .GradientStops(3).Transparency = 0#

                .RotateWithObject = msoFalse

        End With

Thanks,

Eric

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-01-12T16:29:41+00:00

Hi,

In my experience there is no support for line gradients in VBA. Use Open XML SDK to read/set values.


Regards, Shyam Pillai. http://skp.mvps.org

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-01-14T16:01:15+00:00

    Hi,

    Open XML SDK 2.0 for Microsoft Office - http://msdn.microsoft.com/en-us/library/bb448854(office.14).aspx

    Working with PowerPoint and Open XML - http://msdn.microsoft.com/en-us/office/ee358825.aspx


    Regards, Shyam Pillai. http://skp.mvps.org

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-01-14T13:52:50+00:00

    Shyam,

    Can you point out a good intro to XML SDK that will help me learn how to do that?

    Thanks,

    Eric

    Was this answer helpful?

    0 comments No comments