我写了一些函数来向Excel表格中添加折线。然后我发现了奇怪的括号行为。 我将点数组声明和定义为:
Dim points As Variant
Dim sh As Shape
points = Array(Array(10.5, 10.5), Array(20.4, 20.4), Array(5.1, 30.3), Array(10.5, 10.5))
' These both do not work and I get error about wrong type (error 1004) in 2007
' and application defined error 1004 on 2010:
ActiveWorkbook.ActiveSheet.Shapes.AddPolyline points
Set sh = ActiveWorkbook.ActiveSheet.Shapes.AddPolyline(points)
' These work fine:
ActiveWorkbook.ActiveSheet.Shapes.AddPolyline (points)
Set sh = ActiveWorkbook.ActiveSheet.Shapes.AddPolyline((points))
VBA花括号的神奇之处是什么?
在2007和2010版本中测试。