我正在尝试通过以下方式下载另存为的文件框架通知栏的互联网浏览器。
然而,经过大量搜索后,我只找到了点击解决方案save
在框架通知栏上。
到目前为止,我一直在尝试另存为示例站点上的文件:
http://www.tvsubtitles.net/subtitle-114117.html http://www.tvsubtitles.net/subtitle-114117.html
使用以下代码:
' Add referenses
' Microsoft Internet Controls
' Microsoft HTML Object Library
' UIAutomationClient (copy file from C:\Windows\System32\UIAutomationCore.dll to Documents Folder)
#If VBA7 Then
Private Declare PtrSafe Function FindWindowEx _
Lib "user32" _
Alias "FindWindowExA" ( _
ByVal hWnd1 As LongPtr, _
ByVal hWnd2 As LongPtr, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As LongPtr
#Else
Private Declare Function FindWindowEx _
Lib "user32" _
Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) _
As Long
#End If
Sub downloadfilefromeie()
Dim subpage As InternetExplorer
Dim objpage As HTMLDocument
Dim o As CUIAutomation
Dim h As LongPtr
Dim fnb As LongPtr
Dim e As IUIAutomationElement
Dim iCnd As IUIAutomationCondition
Dim Button As IUIAutomationElement
Dim InvokePattern As IUIAutomationInvokePattern
Dim strBuff As String
Dim ButCap As String
Set objshell = CreateObject("Shell.Application")
Set objallwindows = objshell.Windows
Set subpage = New InternetExplorer
For Each ow In objallwindows
'MsgBox ow
If (InStr(1, ow, "Internet Explorer", vbTextCompare)) Then
'MsgBox ow.Hwnd & " " & ow & " " & ow.locationURL
If (InStr(1, ow.locationURL, "tvsub", vbTextCompare)) Then
Set subpage = ow
End If
End If
Next
Set objpage = New HTMLDocument
If subpage Is Nothing Then
Else
Set objpage = subpage.Document
'Debug.Print objpage
'objpage.getElementById("content").Click
Set dl = objpage.getElementsbyclassname("subtable")
Set dltable = dl(0).FirstChild.ChildNodes
Set dlrow = dltable(10).getElementsByTagName("a")(2)
dlrow.Click
While objpage.ReadyState <> "complete"
DoEvents
Wend
End If
Application.Wait (Now() + TimeValue("0:00:05"))
Set o = New CUIAutomation
h = subpage.Hwnd
fnb = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
If fnb = 0 Then Exit Sub
'Debug.Print "type of fnb is " & TypeName(fnb)
Set e = o.ElementFromHandle(ByVal fnb)
'Debug.Print "type of e is " & TypeName(e)
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
'Debug.Print "type of Button is " & TypeName(Button)
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
'Debug.Print "type of InvokePattern is " & TypeName(InvokePattern)
InvokePattern.Invoke
End Sub
我尝试过改变"Save"
to "Save as"
但它不起作用。我的猜测是,我需要以某种方式能够先单击拆分按钮上的箭头,然后再访问“另存为”按钮,但我没有成功做到这一点。
如果有人可以提供解决方案,我将不胜感激。