vba - IE9 自动保存对话框 (vba)

标签 vba internet-explorer automation

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

最佳答案

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

For below showed download

  1. 将文件C:\Windows\System32\UIAutomationCore.dll复制到用户文档,即C:\Users\admin\Documents,然后添加引用UIAutomationClient 到您的宏文件。
  2. 将以下代码粘贴到您的模块中:

        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   
    

请尝试一下。

关于vba - IE9 自动保存对话框 (vba),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26038165/

相关文章:

vba - 如何使用Excel .SaveAs但保留原始工作表名称

arrays - 在工作表列中查找数组值

excel - 如何在 VBA 中有效地编码以访问全局命名范围

html - width = 100% 在 IE、Microsoft Edge 浏览器中无法正常工作

excel - Microsoft Excel - 如何自动填充列中的公式?

python - 在 Sikuli 中匹配某个区域中的模式非常慢

vba - 在 VBA 中处理一个集合的嵌套 For 循环

html - IE 8 的表格格式有什么问题?

html - IE6/7右浮动bug

ruby - 如何在 rspec 中运行多个测试