![](/img/trans.png)
[英]Macro to choose “Save” NOT “save as” when prompted on Internet Explorer 11 message bar at the bottom
[英]VBA - choose save as from the frame notification bar of internet explorer
我正在嘗試通過 Internet Explorer 的框架通知欄下載帶有另存為的文件。 但是經過大量搜索,我只找到了在框架通知欄上單擊save
解決方案。 到目前為止,我一直在嘗試將文件保存為示例站點上的文件:
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"
更改為"Save as"
但它不起作用。 我的猜測是,在訪問另存為按鈕之前,我需要以某種方式能夠首先單擊拆分按鈕上的箭頭,但我沒有成功。 如果有人可以提供解決方案,我們將不勝感激。
我只是嘗試通過鏈接http://www.tvsubtitles.net/download-114117.html下載文件,該鏈接可以在網頁http://www.tvsubtitles.net/subtitle-114117.html上找到,並且它對我有用,這是代碼:
Sub Test_download_tvsubtitles_net()
DownloadFile "http://www.tvsubtitles.net/download-114117.html", ThisWorkbook.Path & "\download-114117.zip"
End Sub
Sub DownloadFile(sUrl, sPath)
Dim aBody
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", sUrl, False
.Send
aBody = .responseBody
End With
With CreateObject("ADODB.Stream")
.Type = 1 ' adTypeBinary
.Open
.Write aBody
.SaveToFile sPath, 2 ' adSaveCreateOverWrite
.Close
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.