简体   繁体   English

Windows 10 IE无法使用旧的VBA代码

[英]Windows 10 IE is not working with old VBA code

I wrote code in VBA a couple years ago to open a website in IE and fill in textboxes with data from an Excel file. 几年前,我在VBA中编写了代码,以在IE中打开一个网站,并用Excel文件中的数据填充文本框。 Unfortunately I am using windows 10 now and this program is not working any more. 不幸的是,我现在正在使用Windows 10,并且该程序无法正常工作。 It opens the website with no problem, but cannot transpose the data into the textboxes. 它可以毫无问题地打开网站,但是不能将数据转置到文本框中。 It simply opens the website and stalls (no data is entered). 它只是打开网站并停滞(没有输入数据)。

The program still works in IE in Windows 7, without any problem. 该程序仍然可以在Windows 7的IE中正常运行。 I tried multiple laptops with Windows 10 and the problem reoccurs. 我在Windows 10上尝试了多台笔记本电脑,问题再次出现。

I tried changing my code at the end from IE.Document.All("Response_123").Value to IE.Document.getElementById("Response_123") to see if that would copy my Excel values into the textbox, but it just remained blank. 我尝试在最后将代码从IE.Document.All("Response_123").Value更改为IE.Document.getElementById("Response_123")以查看是否会将我的Excel值复制到文本框中,但仍为空白。

Sub test()
Dim IE As Object

WebAddress = "https://CONFIDENTIAL_URL.com/"


    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

  Set IE = CreateObject("InternetExplorer.Application")

  IE.Visible = True
  IE.Navigate WebAddress

  While IE.busy
    DoEvents  'wait until IE is done loading page.
  Wend

  Application.wait (Now + TimeSerial(0, 0, 4))

  IE.Document.getElementById("Response_123").Value = ThisWorkbook.Sheets("Sheet1").Range("B5")
End Sub

I would expect the value in my Excel sheet at B5 to be copied into the textbox that has ID "Response_123" (obtained from right clicking textbox > inspect), but it does not copy anything and remains blank. 我希望将Excel工作表中B5处的值复制到ID为“ Response_123”的文本框中(通过右键单击文本框> inspect获得),但是它不会复制任何内容并且保持空白。 Again, I have no problem getting my code to work in Windows 7. 同样,让我的代码在Windows 7中正常工作也没有问题。

I figured out the solution. 我想出了解决方案。 Nothing is wrong with the above code, it was simply the security settings in IE. 上面的代码没什么错,只是IE中的安全设置。 By default they are set to Medium-High, so I changed them to Medium and the code worked fine. 默认情况下,它们设置为中高,因此我将它们更改为中,代码运行正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM