Monday, June 06, 2005

Automatic Mouse Movement on UserForms

I have been using an Excel addin which I had need to automate some
procedures overnight. There are a number a userforms which
have certain commandbuttons to click. Unfortunately, you cannot
access the Command Button click event from external code.

So I searched far and wide for a solution. I found the MouseMove API
routine and adapted it for VBA Userforms.

The principle is that you obtain and enter the dimensions of the UserForm
and Control that you want to access, and then the mouse moves
by itself to that location after a predetermined delay.

Here is a sample file to download if you wish to try it. Open the workbook, click the Start command button and a UserForm is shown. The mouse will click the command UserForm's button automatically.

Labels: ,