API press button

  • Hi. I want to use Excel VBA to enter values into a metronome program. The program is called Presto Metronome and it has a training function that I use regularly. The problem is that the presets don't save in it. Therefore I came up with the idea of storing the variables and entering them automatically from VBA. For example. One exercise may start at 90 bpm and proceed to 120 bpm over 5 minutes with an accent of 3 and another may start at 70 bpm going to 80 bpm over 10 minutes accent 4. I have used Spy++ to find the button handle to take me to the presets screen but can't find how to activate it from Excel VBA. Ideally I'd like to be able to go to the second page and enter the values. The window Handle of the button is 00340818. Any ideas? This is the button that takes me to the training settings page.

  • Quote

    ... I have used Spy++ to find the button handle...

    However, the handle will change every time the program is executed.

    You need to use the FindWindow & FindWindowEx API functions to find the handles assigned to a currently executing application. FindWindow is used to find the application itself using either the Window caption or Class name, then FindWindowEx is used to find the child windows of that parent again using the Class name or Caption/text.

    You can use Spy to get the control names - these are static as they were assigned when the code was written and there's a good, simple intoduction to updating other applictions using FindWindow, FindWindowEx & SendMessage (which you'll also need) here: https://www.ozgrid.com/forum/forum/h...981#post914981

    One thing to watch out for is the fact the control you want to update or click might not be a child of the userform, but in a container like a Frame - so you need to find the userform, then the topmost container, then other containers (if any) before you can find the control.

  • Thanks. I've used API a few times on other programs with sendkeys but sendkeys seems incredibly unreliable in this particular program as it was selecting a different button every time I ran the macro.

  • It is because I can't get sendkeys to work how I want it to on this occasion that I've tried using API instead. Sorry for any confusion. I'm completely new to the API thing

Participate now!

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