Sto provando a scaricare un foglio excel da un sito web. Finora ho raggiunto il risultato fino a quando non faccio clic sul pulsante di download automaticamente (scraping web). Ora ie9 sta scoppiando un salvataggio come schermo. Come lo automatizzo?Automatizza dialoghi saveas per IE9 (vba)
6
A
risposta
9
Si può provare questo come si lavora per me su IE9:
- Copiare il file
C:\Windows\System32\UIAutomationCore.dll
file per gli utenti Documenti cioèC:\Users\admin\Documents
quindi aggiungere riferimentoUIAutomationClient
al file macro. Incolla sotto il codice nel modulo:
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
Prova a vostra fine.
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
Ho inviato i tasti di scelta rapida a IE11.
Nota: il codice non verrà eseguito come previsto se IE non è la finestra attiva sulla macchina in modo che non funzioni in modalità di debug. I tasti di scelta rapida e come inviarli sono di seguito.
- Tasto di scelta rapida: Alt +S
- VBA:
Application.SendKeys "%{S}"
Problemi correlati
- 1. Dialoghi standard WiX
- 2. Flexbox alternativo per IE9
- 3. execCommand SaveAs funziona in Firefox?
- 4. __proto__ per IE9 o IE10
- 5. alternativa a foreignObject per IE9
- 6. HTML/Javascript One Click Print (senza dialoghi)
- 7. Automatizza la configurazione dell'interprete PyDev
- 8. Automatizza l'interoperabilità JavaScript nel Dart
- 9. Automatizza l'installazione dell'estensione Google Chrome
- 10. Automatizza IOS UITableview utilizzando l'appio
- 11. Automatizza xsd.exe durante la compilazione
- 12. Automatizza Jasmine-Node ed express.js
- 13. Twitter Bootstrap 2 form modale dialoghi
- 14. Automatizza conversione txt a xls
- 15. HTML5 saveAs supporto in Google Chrome
- 16. Automatizza Photoshop per inserire il testo dal file
- 17. IE9 ignora il CSS per alcune pagine?
- 18. -ms-transform per IE9 in JavaScript
- 19. Come si automatizza la configurazione di Eclipse?
- 20. Automatizza le schermate su iPhone Simulator?
- 21. Automatizza l'aggiunta di più "sezioni" al manifest?
- 22. Automatizza l'autenticazione oauth senza browser nell'utilità cron
- 23. Automatizza Virtual PC 2007 con PowerShell?
- 24. Automatizza lettura file zip in R
- 25. Console.log IE9 issue
- 26. DXIMageTransform.Microsoft.Matrix sfocata in IE9
- 27. Tooltip Highcharts su IE9
- 28. IE9 e cellspacing
- 29. Sbarazzarsi di "Vuoi riprovare a riaprire le finestre?" dialoghi
- 30. Excel VBA - uscita per loop
quando sto provando ad aggiungere refernence a UIAutomationClient sta gettando un errore: "Errore di caricamento della DLL". – ramses1592
devi copiare il file 'UIAutomationCore.dll' nella tua cartella documenti. – Lifewithsun
'PtrSafe' non viene riconosciuto. Previsto * Previsto: Sottostante o Funzione * – xameeramir