为 IE9 (vba) 自动保存对话 [英] Automate saveas dialogue for IE9 (vba)

查看:27
本文介绍了为 IE9 (vba) 自动保存对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网站下载 Excel 表格.到目前为止,我已经实现了,直到自动单击下载按钮(网络抓取).现在 ie9 正在弹出另存为屏幕.我如何实现自动化?

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 screen. How do i automate that?

推荐答案

你可以试试这个,因为它在 IE9 上对我有用:

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

  1. 复制文件 C:WindowsSystem32UIAutomationCore.dll 文件到用户文档,即 C:UsersadminDocuments 然后添加引用 UIAutomationClient 到您的宏文件.
  2. 将以下代码粘贴到您的模块中:

  1. Copy file C:WindowsSystem32UIAutomationCore.dll file to users Documents i.e C:UsersadminDocuments 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   

最后尝试.

这篇关于为 IE9 (vba) 自动保存对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆