Excel does not execute a button's code when another macro simulates mouse movements & clicks

Z

Zachary_Harrison

Hi all-

I have a button, named Button1, on a worksheet. I have a macro which
does several actions, including moving the mouse cursor over Button1 &
simulating a mouse_down & mouse_up. I use SetCursorPos() and
mouse_event() for this. I find that Button1's code does not execute
when its click is simulated within another macro. Calling
Button1_click() directly is not an option because the Button1_click
code is in a password protected macro which I cannot view.

The end goal is to be able to have the macro do something like this:

1) copy A1's value to A2
2) simulate Button1 being clicked
3) After Button1 is done (known to be < 1minute), copy A3's value to
A4

Does anyone know a fix or workaround for any part of this?

Thank you!

Zachary harrison
 
J

John Bundy

If i understand correctly you just need to insert a module, create a function
and paste the code that is run on button press there such as

Public Function pushButton()
/code here
End Function

then under the button click just type Call pushButton

and you can type the same thing in your code, it will call whether button is
clicked or not.
 
Z

Zachary_Harrison

Thank you for your reply. Either I didn't exlpain my original issue
properly or I'm not understanding your suggestion.

I have an XLS with a button on it. This XLS has password protected
code (XLS1). My goal is to use a second XLS which I will author
(XLS2). XLS2 will manipulate some of the data on the sheets in XLS1,
then simulate pushing the button in XLS1 & collect the results. The
problem is that the simulation of pushing the button doesn't "happen"
until the macro is done.

The solution I came up with is to have XLS2 manipulate the data,
simulate a button press on XLS1 & use the application.onTime method to
have XLS2 pickup the results after a minute.

Regards

Zach
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top