0

所以我在尝试从 API 中获取正确运行的方法时遇到了麻烦。文档说该方法具有以下内容:

updateMethod(Object, String, Int)

对象是包含要更新的项目的工作表或工作簿。String 是项目的名称,而 Int 是将发生的更新类型。

True该方法实际上必须与布尔值一起使用,因为如果更新,它将返回,False否则:

wasUpdated = api.updateMethod(Object, String, Int)

所以我的代码示例是:

Function TestUpdate()

    Dim wasUpdated As Boolean
    Dim Container As Object
    Dim RangeName As String
    Dim refreshType As Integer

    Set Container = ThisWorkbook.Worksheets(1)
    RangeName = "RangeTest"
    refreshType = 0

    wasUpdated = api.updateMethod(Container, RangeName, refreshType)

    If wasUpdate = True Then
        MsgBox "Updated"
    Else
        MsgBox "Failed"
    End If

End Function

我不断收到“需要对象”的运行时错误 424 wasUpdate = ...。我没有正确定义对象吗?或者这可能是 API 本身的问题,我需要联系公司?

谢谢

4

1 回答 1

0

归功于@TimWilliams

问题不在于声明 API 对象,与容器对象无关。

Function TestUpdate()

    Dim wasUpdated As Boolean
    Dim Container As Worksheet
    Dim RangeName As String
    Dim refreshType As Integer
    Dim apiUpdateObject As Object
    Dim apiObject As Object

    Set apiObject = CreateObject("ApiDLL.Object")
    Set apiObject.ParentApp = ActiveWorkbook.Application

    Set apiUpdateObject = apiObject.UpdateMethod
    Set Container = ThisWorkbook.Worksheets(1)
    RangeName = "RangeTest"
    refreshType = 0

    wasUpdated = apiUpdateObject.UpdateNRange(Container, RangeName, refreshType)

    If wasUpdated = True Then
        MsgBox "Updated"
    Else
        MsgBox "Failed"
    End If

End Function

谢谢你们的帮助。

于 2012-09-25T15:55:47.617 回答