Automate saveas dialogue for IE9 (vba)

前端 未结 3 730
遥遥无期
遥遥无期 2020-11-27 08:28

I am trying to download an excel sheet from a website. I have thus far achieved until clicking the download button automatically (web scraping). Now ie9 is popping a save as

3条回答
  •  囚心锁ツ
    2020-11-27 08:53

    You may try this as it is worked for me on IE9:

    For below showed download

    1. Copy file C:\Windows\System32\UIAutomationCore.dll file to users Documents i.e C:\Users\admin\Documents then add reference UIAutomationClient to your macro file.
    2. Paste below code in your module:

          Option Explicit
          Dim ie As InternetExplorer
          Dim h As LongPtr
          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
      
      Sub Download()
          Dim o As IUIAutomation
          Dim e As IUIAutomationElement
          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   
      

    Try at your end.

提交回复
热议问题