Windows 10 Internet Explorer不适用于旧的VBA代码 [英] Windows 10 Internet Explorer is not working with old VBA code

查看:261
本文介绍了Windows 10 Internet Explorer不适用于旧的VBA代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年前,我在VBA中编写了代码,以在IE中打开一个网站,并用Excel文件中的数据填充文本框.不幸的是,我现在正在使用Windows 10,并且此程序无法正常工作.它可以毫无问题地打开网站,但是不能将数据转置到文本框中.它只是打开网站并停滞(不输入数据).

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 anymore. 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).

该程序仍可在Windows 7的IE中正常运行.我尝试了使用Windows 10的多台笔记本电脑,问题再次出现.

The program still works in IE in windows 7, without any problem. I tried multiple laptops with windows 10 and the problem reoccurs.

老实说,我不知道该如何解决.

I honestly don't know how to fix this.

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?

The last line of code should transfer data from the excel file to the textbox in internet explorer, however nothing happens and the textbox remains blank. Do I need to change anything in my code to account for windows 10 IE?

推荐答案

您可以看到您的代码不是以有效的方式编写的.对于替代方法,您可以参考下面的示例,该示例在Windows 10上运行良好.

You can see that your code was not written in an efficient way. For an alternative approach, You can refer example below which is working fine with 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包含哪个值,并检查该行是否成功执行.为了进行测试,请尝试为该文本框分配静态值.

If we talk about your above posted code than you can try to put the break point on that line and try to debug the code. Check that Which value contained by Cell B5 and check whether that line get execute successfully or not. For testing purpose, try to assign static value to that textbox.

这篇关于Windows 10 Internet Explorer不适用于旧的VBA代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆