Windows 10 Internet Explorer is not working with old VBA code
几年前,我在VBA中编写了代码,以在IE中打开一个网站,并用Excel文件中的数据填充文本框。 不幸的是,我现在正在使用Windows 10,并且该程序无法正常工作。 它可以毫无问题地打开网站,但是不能将数据转置到文本框中。 它只是打开网站并停滞(未输入数据)。
该程序仍可在Windows 7的IE中正常运行。 我用Windows 10尝试了多台笔记本电脑,问题再次出现。
老实说,我不知道该如何解决。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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上运行良好。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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包含哪个值,并检查该行是否成功执行。 为了进行测试,请尝试为该文本框分配静态值。