VBA Find Button in Application and Click

  • Hi,


    I need to first search for the button on screen and then click on it. The button is on window in a Java application and the position of button is not fixed. I also know this is very difficult to achieve in VBA alone. I want to use Windows API to achieve this but not sure how should I proceed. Requesting help on this topic.

  • Re: VBA Find Button in Application and Click


    Possibly.


    You will need to use the following API functions:
    FindWindow
    FindWindowEx
    PostMessage


    You will also need a copy of Spy++ to find the Class name and Handle of both the Window and Button. These are needed by FindWindow and FindWindowEx respectively.


    I would suggest you start with Spy++ and check the Window and Button can be found and they do have a Handle and a Classname, if they do, then yes you can click them using code.


    That leaves you with some reading to do.

  • Re: VBA Find Button in Application and Click


    Thanks Cytop I started off with your suggestions.
    But the problem I am facing is that the java application on the screen is not exposing any objects or controls. So I need to search image of button then I may be able to use the Postmessage API you suggested to click the found image using its coordinates.
    Need help to do imagesearch on screen using VBA and APIs.

  • Re: VBA Find Button in Application and Click


    PostMessage does not send a message to a screen region - it sends it to a 'Handle' (which is basically the memory location where the control definition is stored). No handle? Then you can't use PostMessage. The Window is not exposing any controls or objects? Then there's no handle.


    I can't really help with this, Sorry.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!