1

Am stuck and not able to proceed with this. Please find my code below. The code is basically to verify if an element is present in a webpage through VBA. I have created the below sub.

Sub ele_exist(val As String, ele As String)

Select Case val:

Case "byid":
    Set verielement = doc.getElementById(ele)
    If verielement Is Nothing Then
    msgbox("something")
    Else
   msgbox("something")
    End If

Case "byclass":
    Set verielement = doc.getElementsByClassName(ele)
    If verielement Is Nothing Then
    msgbox("something")
    Else
   msgbox("something")
    End If

Case "byname":
    Set verielement = doc.getElementsByName(ele)
    If verielement Is Nothing Then
   msgbox("something")
    Else
   msgbox("something")
    End If

End Select

End Sub

Now when i call this sub it gives syntax error

This is where i call the above sub

Sub start()
Set ie = New InternetExplorer
    With ie
        .navigate "http://www.google.com"
        .Visible = True
        While .Busy Or .readyState <> READYSTATE_COMPLETE
           DoEvents
        Wend
        Set doc = .document
        DoEvents
    End With
    ***ele_exist ("byname","btnK")*** - THIS IS WHERE SYNTAX ERROR IS DISPLAYED AND THE CODE IS DISPLAYED IN RED

End Sub

I even tried converting it to a boolean FUnction rather than sub, but no luck.

Please help

2

1 Answer 1

3

As I mentione in comments, change

ele_exist ("byname","btnK")

to

ele_exist "byname","btnK"

or

Call ele_exist ("byname","btnK")

One more possible way is to use named parameters:

ele_exist val:="byname", ele:="btnK"

For additional explanation check my another post: What is the difference between entering parameters in these four different ways

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.