英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论