Add a gradient to a shape/line

房东的猫 提交于 2020-06-27 10:04:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!