Cliquer sur un bouton d'une application externe avec une macro

Bonjour,

Je suis débutant en VBA et je travaille actuellement sur une macro qui va me permettre de remplir des champs d'une application avec une trame bien définie. Pour le moment j'arrive à activer mon application en premier plan via la macro suivante:

Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow& Lib "user32" (ByVal hwnd&, ByVal wCmd&)
Private Declare Function GetWindowLong& Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd&, ByVal nIndex&)
Private Declare Function GetWindowText& Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd&, ByVal lpString$, ByVal aint&)
Private Const mconMAXLEN = 255

Sub AxelActivate()

Dim hwnd&, Style&, Title$, i&
hwnd = GetWindow(GetDesktopWindow(), 5)

Do While hwnd
Title = GetCaption(hwnd)
If Len(Title) Then
    If GetWindowLong(hwnd, -16) And &H10000000 Then
        If InStr(1, Title, "Axel", 1) Then
        AppActivate Title

        SendKeys "~"

        Exit Sub
        End If

    End If
End If

hwnd = GetWindow(hwnd, 2)
Loop

MsgBox "Vérifier si l'application GIR est ouverte !", vbCritical, "ERROR"

End Sub

Private Function GetCaption(hwnd&) As String
Dim i%, Buffer$: Buffer = String$(254, 0)
i = GetWindowText(hwnd, Buffer, 255)
If i Then GetCaption = Left$(Buffer, i)
End Function

Et il me faut, par la suite, de cliquer sur un bouton sur cette application, en l’occurrence, le bouton "Déclarer incident", pour avoir les champs à remplir, que je compte remplir avec la méthode Sendkeys.

Ma question, est comment je peux cliquer sur ce bouton via VBA?

Merci d'avance pour votre aide.

Cdt;

Bonjour heathcliff

Perso, je pense que vouloir utiliser une application via des "Sendkeys" est une aberration

A moins d'être le seul à vouloir l'utiliser

Bonjour,

C'est une idée initiale, après je vais voir s'il y a d'autres moyens plus fiables. Mais pour le moment je suis encore coincé avec la clique du bouton "Déclarer incident".

Cdt;

Pas de solution pour ce problème?

Rechercher des sujets similaires à "cliquer bouton application externe macro"