使用VBA格式化形状(命令按钮)

huangapple go评论61阅读模式
英文:

Formatting a Shape (Command button) using VBA

问题

我只会翻译代码部分,以下是您提供的代码的翻译:

我只会翻译代码部分,以下是您提供的代码的翻译:

Set t = wsJTO.Range("H5:G6")
Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ShapeRange.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"

请注意,我已经按原文提供了代码的翻译,没有添加其他内容。

英文:

I am simply trying to create a rectangle shape in a specific worksheet, formatting it & assign a macro to it using VBA.

Here goes my attempt :

Set t = wsJTO.Range("H" & 5 & ":G" & 6)    
Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.ShapeRange.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ShapeRange.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"

According to the debugger, there is an error with the third line & I don't seem to understand what's wrong with it. Help would be appreciated

答案1

得分: 2

以下是翻译好的代码部分:

愚蠢的我...我只需摆脱"ShapeRange",因为它没有填充属性如果将来可能对某人有帮助以下代码将完成任务

Set t = wsJTO.Range("H" & 5 & ":G" & 6)

Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"

请注意,我已经保留了代码中的特殊字符,如" 和 &。

英文:

Silly me ... All I had to do was get rid of "ShapeRange" since it doesn't have a fill property. The following code does the job if it might serve someone in the future :

Set t = wsJTO.Range("H" & 5 & ":G" & 6)

Set btn = wsJTO.Shapes.AddShape(msoShapeRectangle, t.Left, t.Top, t.Width, t.Height)
With btn.Fill
    .Visible = msoTrue
    .ForeColor.RGB = RGB(146, 208, 80)
    .Transparency = 0
    .Solid
End With
With btn.ThreeD
    .BevelTopType = msoBevelArtDeco
    .BevelTopInset = 9
    .BevelTopDepth = 6
End With
btn.OnAction = "Module2.Selection_JTO"

huangapple
  • 本文由 发表于 2023年2月10日 05:41:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定