向形状/线条添加渐变 [英] Add a gradient to a shape/line

查看:62
本文介绍了向形状/线条添加渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用VBA在Excel中将渐变添加到线条形状.在 Format Shape 选项下的 Line Color 部分中,可以使用此功能.尽管 Format Shape 选项下存在此功能,但我无法在VBA中重现该功能.我的代码是:

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.

推荐答案

据我所知,这是不可能的.您可以通过VBA为形状的填充设置渐变,但不能为直线设置渐变.您可以创建带有渐变填充且没有边框的细形状,或者必须在VBA之外使用某些形状.(例如VB.NET + OpenXLM SDK.)

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.)

这篇关于向形状/线条添加渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆