【问题标题】:Fill Internet Explorer Pop-Up Window with Excel Data用 Excel 数据填充 Internet Explorer 弹出窗口
【发布时间】:2020-02-24 19:41:46
【问题描述】:

我正在用 Excel 数据填充字段。这个子在其他网站上对我有用。

如何让弹出窗口工作?

我已经阅读了有关此主题的其他几页。我使用的是 IE11。

这是我尝试填写的字段之一的示例。

<input class="form-control" id="firstName" type="text" maxlength="250" data-bind="value:firstName,disable:$parent.readOnly">
Private Sub FillWebForm_xx_AddNewEE()

    Dim ie As Object
    Dim HWNDSrc As Long
    Dim xSheetName As String             

    xSheetName = "Company"

    MsgBox "Open Internet Explorer and navigate to the webpage that contains the fields to be filled, then click Okay."

    'Need to edit this I think: if k-window-title = "New Participant"

    Set ie = GetIE("https://xxx")

    'make browser visible (if existing instance of IE)
    ie.Visible = True

    'Get Window ID for IE so we can set it as activate window
    HWNDSrc = ie.hwnd

    'Set IE as Active Window
    SetForegroundWindow HWNDSrc

    'Add a new employee
    ie.document.all("ssn").Value = ThisWorkbook.Sheets(xSheetName).Range("d32")

    ie.document.all("firstName").Value = ThisWorkbook.Sheets(xSheetName).Range("e32")
    ie.document.all("lastName").Value = ThisWorkbook.Sheets(xSheetName).Range("g32")
    'ie.document.all("suffix").Value = ThisWorkbook.Sheets(xSheetName).Range("h32")
    ie.document.all("dateId").Value = Format$(ThisWorkbook.Sheets(xSheetName).Range("i32").Value, "mm/dd/yyyy")

    ie.document.all("gender").Focus
    ie.document.all("gender").Value = ThisWorkbook.Sheets(xSheetName).Range("j32").Value
    'ie.document.all("gender").FireEvent ("onchange")
    'Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop

    ie.document.all("address1").Value = ThisWorkbook.Sheets(xSheetName).Range("k32")
    ie.document.all("address2").Value = ThisWorkbook.Sheets(xSheetName).Range("l32")
    ie.document.all("city").Value = ThisWorkbook.Sheets(xSheetName).Range("m32")
    ie.document.all("state").Value = ThisWorkbook.Sheets(xSheetName).Range("n32")
    ie.document.all("zip").Value = ThisWorkbook.Sheets(xSheetName).Range("o32")
    'ie.document.all("country").Value = ThisWorkbook.Sheets(xSheetName).Range("p32")
    'ie.document.all("email").Value = ThisWorkbook.Sheets(xSheetName).Range("tbd")
    'ie.document.all("hireDate").Value = Format$(ThisWorkbook.Sheets(xSheetName).Range("q32").Value, "mm/dd/yyyy")

    Set ie = Nothing

    End Sub

这是弹出窗口的样子。

当我右键单击名字字段并单击检查元素时,这就是我所看到的。

【问题讨论】:

  • “弹出窗口”可能是多种类型之一,因此您需要更具体一点,因为我们看不到您的网址
  • 如果没有更多信息,很难说太多。一个成功的结果是什么样的(当它“在其他网站上工作”时你会看到什么)?失败的结果是什么样的(当它“在弹出窗口中不起作用”时,您会看到什么不正确的输出或错误消息)?在每种情况下,您的代码是什么样的?
  • @TimWilliams 发布更多信息。当我单击检查元素时,我看到对 Widget Window 的引用。我不知道这是否有帮助。

标签: javascript excel vba internet-explorer-11


【解决方案1】:

从您的弹出窗口图像来看,它看起来像是一个模型弹出窗口,它是该网页的一部分,而不是一个新窗口。

请尝试参考下面的示例,可能会帮助您打开新的 IE 实例并导航到特定网页并在弹出窗口中填写数据。

Sub website()

On Error GoTo 0

Dim sURL As String
Dim oBrowser As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim oHTML_Element As IHTMLElement

sURL = "C:\Users\Administrator\Desktop\pop_up.html"

Set oBrowser = CreateObject("InternetExplorer.Application")


oBrowser.navigate sURL

Do Until oBrowser.readyState = 4
DoEvents
Loop
oBrowser.Visible = True


oBrowser.Document.getElementById("first_name").Value = "abcd added from VBA..."


'oBrowser.Document.getElementById("Login").Click


End Sub

输出:

请注意,这只是为您提供一个想法的示例。此外,您需要根据您的要求修改代码示例。

其他有用的参考资料:

(1)Automate Internet Explorer (IE) Using VBA

(2)IE (Internet Explorer) Automation using Excel VBA

(3)Learn to write Excel VBA code to automate your web browser.

【讨论】:

  • 感谢您提供的信息。这是附加信息 - 我将尽可能具体。从开始到结束的过程是导航到网站,输入用户名和密码,从列表中选择公司,单击按钮以“添加新参与者”。然后会出现一个新的弹出窗口,其中包含需要填写的表格。我让用户导航到该页面,因为我仍在学习,并且一些用户具有两因素身份验证凭据。我会添加一张图片。
  • 请检查我修改后的答案,我在其中展示了如何将数据输入到模型弹出窗口中。让我们知道,如果您还有其他问题。我们将尽力为此提供建议。
猜你喜欢
  • 1970-01-01
  • 2012-01-25
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多