我想從網站上下載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. 如何自動在另存爲對話框中單擊保存?
- 3. 另存爲或保存DOM對話框在VBA
- 4. Excel VBA保存代碼導致多個保存對話框
- 5. 保存對話框
- 6. 保存對話框
- 7. PHP保存時另存爲對話框
- 8. 自定義下拉對話框(類似於保存對話框)
- 9. jQueryUI日期選擇器在對話框自動對焦在IE9
- 10. 帶自定義過濾器的Word VBA另存爲對話框?
- 11. 如何在MFC中將對話框保存爲對話框
- 12. 對話框保存在Android中,啓動
- 13. Application.GetSaveAsFilename - 自動保存與VBA
- 14. 打開保存爲javascript的對話框
- 15. jquery文件保存爲對話框
- 16. 保存爲Firefox中的對話框
- 17. 保存文件保存對話框
- 18. 打開/保存對話框
- 19. 保存資源對話框
- 20. C++保存對話框
- 21. 通過VBA在Internet Explorer上控制打開/保存/另存爲對話框
- 22. 保存爲對話框保存PDF文件
- 23. 使用SaveAs對話框保存下載文件的vba代碼
- 24. 在保存爲對話框中使用硒自動重命名文件名
- 25. WPF保存對話框(對於Windows 64)
- 26. 如何使用另存爲對話框將Winform保存爲pdf
- 27. AHK:自動化對話框
- 28. 自動關閉對話框
- 29. 對話框自動關閉
- 30. HTA文件保存對話框而不是打開對話框
當我試圖添加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