我写了一些函数来添加一些折线到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))
Run Code Online (Sandbox Code Playgroud)
VBA括号的奇怪魔力是什么?
测试了2007年和2010年版本.