使用Excel VBA在Internet Explorer中自动填写表单

问题描述 投票:0回答:1

我想从excel表中获取值并将它们存储在一个数组中。然后我想从数组中获取值并使用它们来填充Web表单。

我已设法将值存储在数组中,并设法让VBA打开Internet Explorer(IE)

代码运行且不会出现错误,但文本字段未填充,也未单击按钮

(调试器指向[While .Busy]作为错误源,位于WITH块中)

如何填写表格(共有3个文本框填写)?

还有一个下拉菜单,我需要从中选择一个值,但是我需要在继续执行任务的那一部分之前填充文本框。

Sub CONNECT_TO_IE()
the_start:   
Dim ie As Object
Dim objElement As Object
Dim objCollection As Object




acct = GET_CLIENT_NAME()
name = GET_CODE()

Set ie = CreateObject("InternetExplorer.Application")


ie.Visible = True
ie.navigate ("<<my_website>>")
   ie.FullScreen = False

    On Error Resume Next
       Do
       DoEvents
       If Err.Number <> 0 Then
       ie.Quit
       Set ie = Nothing
       GoTo the_start:
       End If
       Loop Until ie.readystate = 4

Application.Wait Now + TimeValue("00:00:10")

ie.Document.getElementbyid("<<field_1>>").Value = "PPP"
ie.Document.getElementbyid("<<field_2>>").Value = "PPP"
ie.Document.getElementbyid("<<field_3>>").Click


Set ie = Nothing
End Sub
excel vba excel-vba internet-explorer ui-automation
1个回答
0
投票

更新:原因是这不起作用是因为网站的HTML中有一些设置不允许自动化发生,所以我所拥有的任何代码版本都是正确的,但它们注定要失败。所以你在这方面是正确的@TimWilliams。

我知道这是因为我试图访问的网站是在安全的服务器/虚拟机上。我编辑了代码以填写谷歌搜索栏,它在虚拟机上不起作用,但是当我在本地运行相同的代码时,它工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.