【发布时间】: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