[英]Windows 10 Internet Explorer is not working with old VBA code
幾年前,我在VBA中編寫了代碼,以在IE中打開一個網站,並用Excel文件中的數據填充文本框。 不幸的是,我現在正在使用Windows 10,並且此程序無法正常工作。 它可以毫無問題地打開網站,但是不能將數據轉置到文本框中。 它只是打開網站並停滯(沒有輸入數據)。
該程序仍然可以在Windows 7的IE中正常工作。 我嘗試使用Windows 10的多台筆記本電腦,問題再次出現。
老實說,我不知道該如何解決。
DoEvents
WebAddress = "CONFIDENTIAL URL HERE" & WebID & "&t="
Dim IE As Object
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate WebAddress
IE.Visible = True
While IE.busy
DoEvents 'wait until IE is done loading page.
Wend
Application.Wait (Now + TimeSerial(0, 0, 4))
IE.Document.All("Response_123").Value = ThisWorkbook.Sheets("Sheet1").Range("B5")
最后一行代碼應將數據從excel文件傳輸到Internet Explorer中的文本框,但是什么也沒有發生,因此文本框保持空白。 我是否需要更改我的代碼中的任何內容以說明Windows 10 IE?
您可以看到您的代碼不是以有效的方式編寫的。 對於替代方法,您可以參考下面的示例,該示例在Windows 10上運行良好。
Dim IE As Object
Sub demo()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "C:\Users\Administrator\Desktop\sample.html"
While IE.Busy
DoEvents
Wend
wait 1
IE.Document.getElementById("firstname").Value = ThisWorkbook.Sheets("Sheet1").Range("A1")
wait 1
IE.Document.getElementById("lastname").Value = ThisWorkbook.Sheets("Sheet1").Range("A2")
wait 1
IE.Document.getElementById("submit_btn").Click
IE.Quit
Set IE = Nothing
Application.ScreenUpdating = True
End Sub
Private Sub wait(seconds As Long)
Dim endTime As Date
endTime = DateAdd("s", seconds, Now())
Do While Now() < endTime
DoEvents
Loop
End Sub
輸出:
如果我們談論您上面發布的代碼,則可以嘗試將斷點放在該行上並嘗試調試代碼。 檢查單元格B5包含哪個值,並檢查該行是否成功執行。 為了進行測試,請嘗試為該文本框分配靜態值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.