我試圖把一個宏從vba形狀,但我收到這個錯誤「無效的財產使用」,爲什麼?
類CContainer代碼:Shape.OnAction上的屬性錯誤的無效使用
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
你錯過了等號嗎? t.OnAction =「MsgCall」 –
不,這會導致「應用程序定義/對象錯誤」,但感謝@科迪G。 – Jey
Set sr = w.Shapes.Range(Array(「ShapeExample」,「TextShapeExample」))中的應用程序已定義/對象錯誤。 –