【发布时间】:2017-04-08 15:00:19
【问题描述】:
我正在使用 Intranet。使用 VBA 我必须关闭列表中的某个日期。
- 我已选择日期。然后单击要关闭的链接(不是按钮),该链接会触发 javascript。
已选择所有日期:
html.getElementsByName("selectall")(0).Click
点击关闭日期的链接。
html.getElementsByTagName("a")(0).Click
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
javascript的一部分
{
//alert(xxx)
document.first.deletepids.value = xxx
window.open('closeallocation.asp?hotelid='+hotelid+'&roomtype='+roomtype+'&allocxid='+allocxid,'','toolbar=no,scrollbars=yes,width=500,height=330,top=50,left=80')
//window.open('closeallocation.asp?deletepids='+xxx+'&hotelid='+hotelid+'&allocxid='+allocxid)
}
else
{
if(confirm("Room(s) already having bookings for required dates.Do you wish to continue ?"))
{
document.first.deletepids.value = xxx
window.open('closeallocation.asp?hotelid='+hotelid+'&roomtype='+roomtype+'&allocxid='+allocxid,'','toolbar=no,scrollbars=yes,width=500,height=330,top=50,left=80')
}
else
return false;
}
- 它会打开一个新窗口。
如何使用 VBA 在同一窗口中打开 javascript 窗口,或者在新窗口中打开时如何获取元素或设置值或单击新窗口的元素?
我尝试使用 shell 窗口搜索所有打开的带有 title 和 locationurl 的窗口,但由于某种原因我没有找到那个特定的窗口。
Dim ow As ShellWindows
Dim fw As Variant
Dim html As HTMLDocument
Dim ie As InternetExplorer
Set ie = New InternetExplorer
Set ow = New ShellWindows
For Each fw In CreateObject("Shell.application").Windows
'On Error GoTo ErrorMsg
If fw = "Internet Explorer" Then
If InStr(fw.LocationURL, "displayhotelallocsummary.asp") <> 0 Then
Exit For
End If
End If
Next fw
Set ie = fw
Set html = ie.document
请指教。
【问题讨论】:
-
我真的没有粗鲁的意思,但你应该认真考虑升级你所知道的关于 Web 开发的一切。这看起来很像我在 1999 年左右所做的事情,当时也感觉很糟糕。这是新软件,还是您从大约 10 到 15 年前开始制作它的人那里继承的?通过使用现代方法重做,您将为您的客户/雇主节省很多钱,并为您自己减轻很多压力。
-
嗨安德烈斯。我一点也不生气。我完全理解你的担心。你不是第一个对我的代码有这个想法的人。但是 Javascript 是由第三方编写的,我只是想让数据变得优秀。公司不想花更多的钱聘请一名专家程序员。所以我一边学习一边工作。我很高兴我正在学习。听起来你一定是一个非常优秀的程序员。你认为这个问题有解决方案吗?
标签: javascript vba internet-explorer browser-automation childwindow