VBA Code to Set Line Gradient?

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

Answer
Answer

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
Regards
Shyam Pillai

http://skphub.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated November 30, 2023 Views 2,309 Applies to: