我试图将宏放到vba的形状中,但是我收到了这个错误"无效的使用属性",为什么?
CContainer类代码:
Option Explicit
Sub CreateContainer()
Dim s As Shape ' shape container
Dim t As Shape 'text container
Dim sr As Variant 'container for grouping
Dim w As Worksheet
Set w = ActiveWorkbook.Worksheets(1)
Set s = w.Shapes.AddShape(msoShapeRectangle, 10, 10, 100, 100)
With s
s.Fill.ForeColor.RGB = RGB(255, 255, 255)
s.Line.ForeColor.RGB = RGB(100, 100, 100)
s.Line.DashStyle = msoLineDash
s.Line.Style = msoLineSingle
s.Line.Weight = 0.5
s.Name = "ShapeExample"
End With
Set t = w.Shapes.AddTextbox(msoTextOrientationHorizontal, s.Left + 10, s.Top + 10, s.Width - 20, 20)
With t
t.Line.ForeColor.RGB = RGB(100, 100, 100)
t.Line.DashStyle = msoLineDash
t.TextFrame.Characters.Text = "Connector"
t.TextFrame.Characters.Font.Size = 10
t.TextFrame.HorizontalAlignment = xlHAlignCenter
t.Name = "TextShapeExample"
End With
Set sr = w.Shapes.Range(Array("ShapeExample", "TextShapeExample")).Group
sr.Name = "ContainerExample"
t.OnAction "MsgCall" '<-- here the error occurs
End Sub
Sub MsgCall()
MsgBox "Hello There"
End Sub
以及我想要称之为的模块:
Option Explicit
Sub example()
Dim connector As CContainer
Set connector = New CContainer
connector.CreateContainer
End Sub
答案 0 :(得分:0)
我将你的代码改为:
UIelement
现在,我收到了另一个错误:With Worksheets(1).Shapes(1)
.OnAction "MsgCall" '<-- no more error here
End With
代码:
Grouping is disabled for selected shapes