Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
869 connectés 

  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Excel VBA, API SendMessage ne fonctionne pas

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Excel VBA, API SendMessage ne fonctionne pas

n°1943751
jojo869
Posté le 23-11-2009 à 21:31:50  profilanswer
 

Bonsoir,
 
A partir d'excel j'ouvre un fichier Word, Internet explorer ouvre automatiquement la fenetre de telechargement.(la fenetre standard "Ouvrir, Enregistrer, Annuler" )
 
J'arrive à extraire le handle de la fenetre et le handle du bouton mais rien ne se passe... Mon bouton Ouvrir n'est pas actionné.
 
Voici le code :
 
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _  
ByVal lpWindowName As String) As Long  
 
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _  
(ByValhwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long  
 
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _  
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long  
 
Public Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long  
Public Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long  
Public Const BM_CLICK = &HF5  
 
Sub ApplicationPremierPlan()  
  Dim hwnd, hwnd_button As Long  
  hwnd = FindWindow(vbNullString, "Calculatrice" ) '"Téléchargement de fichiers" )  
  MsgBox hwnd  
  If hwnd > 0 Then  
    hwnd_button = FindWindowEx(hwnd, 0, "Button", "Ou&vrir" )  
  SendMessage hwnd_button, BM_CLICK, 0, 0
  End If  
End Sub  
 
 
Merci de votre aide à tous.

mood
Publicité
Posté le 23-11-2009 à 21:31:50  profilanswer
 

n°1944262
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 25-11-2009 à 00:07:06  profilanswer
 

essaie

Code :
  1. SetActiveWindow(hwnd)
  2. SendMessage(hwnd_button, BM_CLICK, 0, ByVal 0& )


(n'oublie pas de déclarer la fonction SetActiveWindow() )


Message édité par Harkonnen le 25-11-2009 à 00:09:55

---------------
J'ai un string dans l'array (Paris Hilton)
n°1944276
jojo869
Posté le 25-11-2009 à 07:58:41  profilanswer
 

Merci beaucoup pour cette solution mais elle ne fonctionne pas, je l'avais essayée.
 
Il doit pourtant y avoir une solution bon sang...
 
J'ai essayer aussi avec sendkeys mais c'est pareil...
 
J'en ai marre...

n°1944277
jojo869
Posté le 25-11-2009 à 08:04:15  profilanswer
 

Voici ce que j'ai fait :
 

Code :
  1. Sub TestFull()
  2. Dim i As Integer
  3. Dim IE As InternetExplorer
  4. Dim maPageHtml As HTMLDocument
  5. Dim Helem As IHTMLElementCollection
  6. Dim ParentWndHandle As Long
  7. On Error Resume Next
  8. 'Call listerFenetres_IE_Ouvertes
  9. 'Call listerFenetres_IE_Ouvertes
  10. Set IE = CreateObject("InternetExplorer.Application" )
  11. IE.Visible = True
  12. IE.navigate "http://127.0.0.1/Doc1.doc"
  13. Do Until IE.readyState = READYSTATE_COMPLETE
  14. DoEvents
  15. Loop 'attend la fin du chargement
  16. IE.Visible = True
  17. 'Fonction récuperation du handle et activation du bouton
  18. Call FindWindow("#32770", "Téléchargement de fichier" )
  19. ParentWndHandle = FindWindow("#32770", "Téléchargement de fichier" )
  20. If ParentWndHandle <> 0 Then
  21.     Dim ChildWndHandle As Long
  22.     SetForegroundWindow ParentWndHandle
  23.     Pause 2 'Fonction pause de 2 seconde
  24.     SendKeys "%v", True
  25. End If
  26. End Sub


Le début de la fonction ouvre ma page web
Ensuite, sous le commentaire 'Fonction récuperation du handle et activation du bouton', je récupère le handle etc...
 
Cette fonction fonctionne si j'ouvre à la main ma fenetre de telechargement et si je lance à la main ma fonction...
 
Merci de votre aide...


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  VB/VBA/VBS

  Excel VBA, API SendMessage ne fonctionne pas

 

Sujets relatifs
Redirection 301 qui ne fonctionne pas : help !filtrage automatique sur excel par bouton et action VBA
Macro excelVBA Excel - activecell étirement
Importer des données d'un fichier HTML dans ExcelTransfert Fichier Texte dans ACCESS depuis vba Excel
[VBA] Exécution macro dans un autre classeur[VBA] Rechercher une valeur dans une colonne ?
Plus de sujets relatifs à : Excel VBA, API SendMessage ne fonctionne pas


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR