You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerPoint VBA运行时错误-2147024809(80070057):参数类型错误如何解决?

VBA AddCurve 运行时错误 '-2147024809 (80070057)' 解决

问题场景

以下VBA代码尝试在PPT幻灯片中添加曲线:

Sub makeCurve()
  Const numpts = 7
    Dim pts(1 To numpts, 1 To 2 )
    For i = 1 to numpts
      pts(i, 1) = 10 + i * 72 / 2
      pts(i, 2) = 10 + i * 72 / 2
    Next
    Set myDocument = ActivePresentation.Slides(1)
    With myDocument.Shapes.AddCurve(pts).Line
      .ForeColor.RGB = RGB(0, 0, 0)
      .Weight = 1.5
    End With
End Sub

运行时弹出错误:

Run-time error '-2147024809 (80070057)':
The specified parameter has an incorrect data type

错误原因

Shapes.AddCurve方法要求传入的参数是一维Variant数组,数组中的每个元素需是包含X、Y坐标的子数组(或ShapePoint对象)。原代码使用的二维数组不符合该方法的参数类型要求,导致类型不匹配错误。

解决代码

将数组定义改为一维Variant数组,循环中为每个元素赋值坐标数组:

Sub makeCurve()
  Const numpts = 7
    Dim pts(1 To numpts) As Variant
    For i = 1 To numpts
      pts(i) = Array(10 + i * 72 / 2, 10 + i * 72 / 2)
    Next
    Set myDocument = ActivePresentation.Slides(1)
    With myDocument.Shapes.AddCurve(pts).Line
      .ForeColor.RGB = RGB(0, 0, 0)
      .Weight = 1.5
    End With
End Sub

说明

修改后,pts数组的每个元素都是独立的坐标数组,完全符合AddCurve方法对参数的数据类型要求,运行即可正常生成曲线。


内容的提问来源于stack exchange,提问作者elscan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 05:32:16