将 HTML 元素传递给过程(作为参数)

Passing HTML Elements to Procedures (as parameter)

我想调用一个过程并将一些 HTML 元素传递给它。

如果我这样调用过程 SimpleSearch (eNames) 那么 For Each 语句 returns 错误

Object doesn't support this property or method

Sub Navigate()    
    Set eNames = IE.Document.getElementsByTagName("button")
    SimpleSearch (eNames)
End Sub


Sub SimpleSearch(ssitems)
    For Each ssitem In ssitems
        If ssitem.innerText = "Simple Search" Then
            ssitem.Focus
            ssitem.Click
            Exit For
        End If
    Next ssitem

    Do While IE.Busy
    Loop
    Do While IE.ReadyState < 4
    Loop
End Sub

从过程调用中删除括号:

Sub Navigate()
    Set eNames = IE.Document.getElementsByTagName("button")
    SimpleSearch eNames
End Sub

在VBA 函数中使用括号,但过程不使用:

Sub Test()
    MyString = MyFunction("parameter")   'function call with parenthesis
    MyProcedure "parameter"              'procedure call without parenthesis
End Sub


Function MyFunction(Parameter As String) As String
    'some code
    MyFunction = "Return Value"   'a function should return a value
End Function

Sub MyProcedure(Parameter As String)
    'some code
End Sub