J'essaie de télécharger une feuille Excel d'un site Web. J'ai jusqu'à présent réalisé jusqu'à ce que cliquez sur le bouton de téléchargement automatiquement (raclage Web). Maintenant, IE9 apparaît une sauvegarde d'écran. Comment puis-je l'automatiser? P>
3 Réponses :
Vous pouvez essayer cela car il est fonctionné pour moi sur IE9:
c: \ windows \ system32 \ uiautomationcore.dll code> fichier sur les documents d'utilisateurs c'est-à-dire c: \ utilisateurs \ admin \ documents code> ajoutez ensuite référence uautomationclient
/ code> à votre fichier macro. li>
-
coller en dessous du code de votre module: p>
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
Lorsque j'essaie d'ajouter une référence à uautomationclient, je lance une erreur: "Erreur lors du chargement de la DLL".
Vous devez copier le fichier uiautomationcore.dll code> dans votre dossier de document.
ptrsafe code> ne se reconnaît pas. Il dit attendu: sous ou fonction i>
Avertir! Si vous êtes étranger, vous devez modifier correctement le nom du bouton au lieu de "Enregistrer" SET "SET" SET ICND = O.CREATTEPROPERTYTYCONTION (UIA_NAMPROPERTYID, "") "
Comment fermer la fenêtre après si h = 0 puis quitte Sub code>?
'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
J'ai envoyé les touches de raccourci sur IE11. P>
Remarque: le code ne fonctionnera pas comme vous l'attendez si c'est-à-dire que c'est-à-dire la fenêtre active de votre machine, de sorte qu'il ne fonctionnera donc pas pendant le mode de débogage. Les touches de raccourci et comment les envoyer sont ci-dessous. P>
Application.Sendkeys "% {s}" code> li>
ul>