我想从网站上下载Excel工作表。我迄今为止实现了自动点击下载按钮(网络抓取)。现在ie9弹出屏幕保存。我如何自动化?为IE9(vba)自动保存对话框
6
A
回答
9
,因为它是为我工作在IE9你可以试试这个:
- 复制文件
C:\Windows\System32\UIAutomationCore.dll
文件到用户的文档即C:\Users\admin\Documents
然后添加到您的宏文件的参考UIAutomationClient
。 粘贴下面的代码你的模块中:
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
试着在你结束。
0
'This is a working code for vba in excel 2007 to open a file
'But you need to add the "UIAutomationCore.dll" to be copied
'from "C:\Windows\System32\UIAutomationCore.dll" into the
'path "C:\Users\admin\Documents"
'The path where to copy may be different and you can find it when you check on
'the box for UIAutomationClient - the location is given under it.
'Tools-references
Option Explicit
Dim ie As InternetExplorer
Dim h As LONG_PTR
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LONG_PTR, ByVal hWnd2 As LONG_PTR, ByVal lpsz1 As String, ByVal lpsz2 As String) As LONG_PTR
Sub click_open()
Dim o As IUIAutomation
Dim e As IUIAutomationElement
Dim sh
Dim eachIE
Do
Set sh = New Shell32.Shell
For Each eachIE In sh.Windows
' Check if this is the desired URL
' Here you can use your condition except .html
' If you want to use your URL , then put the URL below in the code for condition check.
' This code will reassign your IE object with the same reference for navigation and your issue will resolve.
If InStr(1, eachIE.LocationURL, "<enter your page url>") Then
Set ie = eachIE
Exit Do
End If
Next eachIE
Loop
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, "Open")
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
0
我将快捷键发送到IE11。
注意:如果IE不是您计算机上的活动窗口,代码将无法按预期运行,因此在调试模式下它将不起作用。下面是快捷键以及如何发送它们。
- 快捷键:Alt键+小号
- VBA:
Application.SendKeys "%{S}"
相关问题
- 1. 如何使用VBA在IE11中自动保存另存为对话框?
- 2. 另存为或保存DOM对话框在VBA
- 3. Excel VBA保存代码导致多个保存对话框
- 4. 保存对话框
- 5. 自定义下拉对话框(类似于保存对话框)
- 6. jQueryUI日期选择器在对话框自动对焦在IE9
- 7. 如何在MFC中将对话框保存为对话框
- 8. 对话框保存在Android中,启动
- 9. jquery文件保存为对话框
- 10. 保存资源对话框
- 11. 打开/保存对话框
- 12. 保存对话框输入
- 13. 通过VBA在Internet Explorer上控制打开/保存/另存为对话框
- 14. 保存为对话框保存PDF文件
- 15. 在保存为对话框中使用硒自动重命名文件名
- 16. WPF保存对话框(对于Windows 64)
- 17. IE9不保存会话数据
- 18. C#保存图片框与保存对话框
- 19. VBA对话框自动回答解决方案
- 20. 在IE9中防止onbeforeunload对话框
- 21. IE9中的Struts2-jQuery对话框错误?
- 22. VBA Word - 另存为对话框初始文件名
- 23. VBA Word 2003对话框
- 24. 保存/ [另存为]对话框下载使用wordpress
- 25. 另存为对话框IEXPLORER如何保存htm文件
- 26. VBA使用保存对话框创建带有文件名的新工作表并保存为CSV格式
- 27. C++ WinAPI保存和打开对话框
- 28. 挂钩保存文件对话框
- 29. Setup.exe的ClickOnce保存对话框
- 30. 在Silverlight中保存对话框
当我试图添加refernence到UIAutomationClient它抛出一个错误: “加载DLL时出错”。 – ramses1592 2014-11-21 13:42:56
你必须将UIAutomationCore.dll文件复制到你的文档文件夹中。 – Lifewithsun 2014-11-21 15:17:26
'PtrSafe'没有被识别。它说*预期:子或功能* – xameeramir 2015-09-15 11:15:58