自动保存IE9的对话框(vba) [英] Automate saveas dialogue for IE9 (vba)
本文介绍了自动保存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:
- 复制文件
C:\ Windows \ System32 \ UIAutomationCore.dll
文件给用户文件即C:\ Users \admin \Documents
然后将引用UIAutomationClient
添加到您的宏文件中。 -
粘贴模块中的代码:
- Copy file
C:\Windows\System32\UIAutomationCore.dll
file to users Documents i.eC:\Users\admin\Documents
then add referenceUIAutomationClient
to your macro file. 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屋!
查看全文