简体   繁体   中英

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. Unfortunately I am using windows 10 now and this program is not working any more. 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. I tried multiple laptops with Windows 10 and the problem reoccurs.

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.

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. Again, I have no problem getting my code to work in Windows 7.

I figured out the solution. Nothing is wrong with the above code, it was simply the security settings in IE. By default they are set to Medium-High, so I changed them to Medium and the code worked fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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