【问题标题】:Filename from Frame Notification Bar帧通知栏的文件名
【发布时间】:2020-02-05 06:19:04
【问题描述】:

有谁知道是否有一种方法可以使用 hwnd 从 IE11 的“框架通知栏”中提取文件名?下面的代码效果很好,但我试图找到一种更好的方法来查找文件(动态命名),然后从下载文件夹中提取最新的文件。提前致谢!

Sub SaveFile(IE As InternetExplorerMedium)
Dim o As IUIAutomation, buffer As String, length As Long, result As Long, e      As IUIAutomationElement, h As Long
Set o = New CUIAutomation
h = IE.hWnd
h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
If h = 0 Then Exit Sub
Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")
Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke
End Sub

【问题讨论】:

    标签: vba internet-explorer


    【解决方案1】:

    我知道这是一个老问题,但由于没有答案,而且我找到了获得它的方法,我认为分享它是件好事。

    您要查找的元素是Notification bar Text

    我的解决方案基于本教程:

    https://www.mrexcel.com/board/threads/using-uiautomationclient-to-automate-the-save-as-file-download-in-ie11.1086615/

    添加这些声明:

            Dim iCnd2 As IUIAutomationCondition
            Dim iCnd3 As IUIAutomationCondition
            Dim iCnd2and3 As IUIAutomationCondition
            Dim NotificationBarText As IUIAutomationElement
    

    在Set e = o.ElementFromHandle(ByVal h) 之后添加:

            Set iCnd2 = o.CreatePropertyCondition(UIA_NamePropertyId, "Notification bar Text")
            Set iCnd3 = o.CreatePropertyCondition(UIA_ControlTypePropertyId, UIA_TextControlTypeId)
            Set iCnd2and3 = o.CreateAndCondition(iCnd2, iCnd3)
            Set NotificationBarText = e.FindFirst(TreeScope_Descendants, iCnd2and3)
            NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)
            baseUrl = Mid(Mid(IE.LocationURL, InStr(IE.LocationURL, "//") + 2), 1, InStr(Mid(IE.LocationURL, InStr(IE.LocationURL, "//") + 2), "/") - 1)
            FileName = Replace(Replace(NotificationBarTextString, "Do you want to open or save ", ""), " from " & baseUrl & "?", "")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 2011-09-01
      • 2013-07-13
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多