excel - VBA 运行时错误 13:使用 HTMLDocument 作为参数调用函数时类型不匹配
问题描述
下面的代码在一台机器上运行良好,并在使用两个参数调用函数时在第二台机器上返回错误(使用一个参数调用时,它运行良好)。该功能在另一个模块中。有人可以给我一个建议吗?
两台机器都运行 Excel 2016 和 IE11。
Dim ie As InternetExplorer
Dim htmlDoc As MSHTML.HTMLDocument
Set ie = New InternetExplorerMedium
With ie
.Silent = True
.navigate serverURL 'URL as string
.Visible = False
End With
Set htmlDoc = ie.document
Call WaitForLoad(ie) 'this works fine
For Each htmlElement In htmlDoc.getElementsByTagName("input")
If htmlElement.Type = "submit" Then htmlElement.Click: Exit For
Next
Call WaitForLoad(ie, htmlDoc) 'this returns Run-time error 13: Type mismatch
功能:
Public Function WaitForLoad(browser As InternetExplorer, _
Optional ByVal doc1 As MSHTML.HTMLDocument, _
Optional ByVal doc2 As MSHTML.HTMLDocument) _
As Variant
If Not browser Is Nothing Then
Call LoadTimeoutSettings
Do
DoEvents
Loop Until (browser.readyState = READYSTATE_COMPLETE) Or (Now > StopTime)
End If
If Not doc1 Is Nothing Then
Call LoadTimeoutSettings
Do
DoEvents
Loop Until (doc1.readyState = "complete") Or (Now > StopTime)
End If
If Not doc2 Is Nothing Then
Call LoadTimeoutSettings
Do
DoEvents
Loop Until (doc2.readyState = "complete") Or (Now > StopTime)
End If
End function
Function LoadTimeoutSettings()
StartTime = Now
StopTime = StartTime + TimeValue(TimeOut) 'TimeOut="00:00:15"
End Function
解决方案
推荐阅读
- html - 如何避免在 html 主题构建中重复引导类
- json - 寻找将草图形状路径点(json格式)转换为svg路径的模式或公式
- swift - 如何快速将字符串转换为 char*?
- python - SQLAlchemy 视图处理
- codenameone - 多代号一CSS
- facebook - Facebook Ads API - 实时获取广告账户余额
- automated-tests - 自动化测试 - Katalon 工作室
- python - 是否有任何与 haskell 的 "it" 等效的 python 来获取 REPL 中的最后一个成功命令
- javascript - 为什么当用户关闭 chrome 中的选项卡时显示弹出窗口?
- javascript - 在 WebAssembly 中写入文件