簡體   English   中英

Excel VBA:錯誤 438“對象不支持此屬性或方法

[英]Excel VBA: Error 438 "object doesn't support this property or method

此代碼用於使用 Excel VBA 在 Web 表單中輸入值:

Sub Call_Site(var1 As String)
Dim oHTML_Element As Object 'IHTMLElement
Dim sUrl As String

sUrl = "https://www.example.com/page"
Set oBrowser = CreateObject("InternetExplorer.Application") 'New InternetExplorer
oBrowser.silent = True
'oBrowser.timeout = 60
oBrowser.navigate sUrl
oBrowser.Visible = False

With oBrowser
    Do While .Busy Or .ReadyState <> 4: Loop
End With

Set HTMLDoc = oBrowser.document.getElementsByClassName("nexcel")(0)

With HTMLDoc
   HTMLDoc.getElementById("var1").Value = var1
End With
Exit Sub

它發生在這一行: HTMLDoc.getElementById("var1").Value = var1

正在返回錯誤:

Error 438 "object doesn't support this property or method

這只是有時發生。

我不明白為什么錯誤只發生在有時(通常是在它很關鍵的時候)以及我可以做些什么來防止它。

讓瀏覽器可見,這一切似乎都很正常。

在類似的答案中,我沒有找到解決方案。

使用oHTML_Element.Document.all.Item("var1").Value = var1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM