我尝试导航到Photovoltaic Geographical Information System - Interactive Maps(已完成),填写我需要(已完成)的字段,按 Caluclate 与网页输出选项(完成)。
然后会弹出一个包含数据的窗口。我想将数据表的内容下载到我的工作表并关闭两个窗口
我只能使用InternetExplorer.visible = True
执行此操作(使用ShellWindows
循环,有2个窗口=>正确,但我不希望窗口可见)。但是当InternetExplorer.visible = False
只有主窗口时,而不是popup =>不正确。
我的问题是: 如何指向隐藏弹出窗口并从中下载数据?可能使用与 ShellWindows 不同的东西。
代码
Sub PVGISDownload()
Dim IE As New SHDocVw.InternetExplorer
Dim shellWins As New ShellWindows
With IE
.Navigate "http://re.jrc.ec.europa.eu/pvgis/apps4/pvest.php"
.Visible = False 'false will not work correctly, unable to get to the popup
Do While IE.readyState <> 4: DoEvents: Loop
With .document
.getElementsByname("address")(0).Value = "nitra"
Set htmlColl = .getElementsBytagname("input")
For Each htmlInput In htmlColl
If Trim(htmlInput.Type) = "submit" And htmlInput.Value = "Search" Then
htmlInput.Click 'set location
Exit For
End If
Next htmlInput
Do While IE.readyState <> 4: DoEvents: Loop
'set options (among others)
.getElementsByname("outputchoicebuttons")(0).Click
Do While IE.readyState <> 4: DoEvents: Loop
'! Blocked by automatic popups (enabled by hand for now)
.getElementsByname("PVchoicesubmit")(0).Click 'click for the Popup window with data
Debug.Print shellWins.Count 'with visible = 2, with hidden = 1
End With '.document
End With 'IE
'check all opened windows and find the one with PV output
For Each shlWindow In shellWins
'...code to process the data
End Sub