[英]Error while calling sub in vba
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.
代码基本上是通过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
现在,当我调用此子时,它会出现
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. 我甚至尝试将它转换为布尔值而不是sub,但没有运气。
Please help 请帮忙
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 有关其他说明,请查看我的另一篇文章: 以这四种不同方式输入参数之间的区别是什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.