问题
I am attempting to add a gradient to a line shape in Excel using VBA. This feature is available in the Line Color
section under the Format Shape
option. Despite this feature existing under the Format Shape
option, I am unable to reproduce the functionality in VBA. My code is:
With ActiveSheet.Shapes("Straight Connector 4")
.Line.ForeColor.RGB = RGB(193, 193, 193)
.Line.Transparency = 0.25
.Line.Visible = msoTrue
.Line.ForeColor.SchemeColor = 24
.Line.BackColor.SchemeColor = 34
.Line.GradientStops.Insert RGB(255, 0, 0), 0.25 ' Creates error
.Line.Gradient.ColorStops.Add (1) ' Creates error
End With
I know you can easily add a gradient to the shape fill but all search results are returning nothing when wanting to add a gradient to a shape line. Any ideas are more than welcome.
回答1:
As far as I know, it is not possible. You can set a gradient for a shape's fill through VBA, but you can't do it for a line. You can either create a thin shape with gradient fill and no border, or you will have to use something outside VBA. (Eg. VB.NET + OpenXLM SDK.)
来源:https://stackoverflow.com/questions/31621765/add-a-gradient-to-a-shape-line