ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I code VBA to hit button on a different worksheet? (https://www.excelbanter.com/excel-programming/369677-how-do-i-code-vba-hit-button-different-worksheet.html)

[email protected]

How do I code VBA to hit button on a different worksheet?
 

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how to
execute the button.

Run or Call don't work.

Help.

TIA.


Dave Peterson

How do I code VBA to hit button on a different worksheet?
 
If the button is from the Forms toolbar, then just rightclick on that button and
assign your macro to it.

If the commandbutton is from the Control toolbox toolbar, just double click on
that commandbutton and put your code in that window.

(you'll have to be in design mode for that, though.)

wrote:

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how to
execute the button.

Run or Call don't work.

Help.

TIA.


--

Dave Peterson

NickHK

How do I code VBA to hit button on a different worksheet?
 
If you are trying to fake a button click, rather than Dave's suggestion of
code location, you have a couple of options:
1 - Calling the code for the click event;
Call cmdButton_Click
But you will have change the _Click routine from Private (default) to Public
so it can be seen outside the module.
Also reference the correct WB/WS as required.

2 - Some people feel it is wrong to call events like the above. If so use
cmdButton.Value=True

NickHK

wrote in message
oups.com...

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how to
execute the button.

Run or Call don't work.

Help.

TIA.




[email protected]

How do I code VBA to hit button on a different worksheet?
 

Yes, I am trying to fake a button click. The worksheet (there are many
worksheets, otherwise I would just click the button myself) is
protected so I can't change the code.

How do I go about doing #2? Would that fake a click?

Thanks.

NickHK wrote:
If you are trying to fake a button click, rather than Dave's suggestion of
code location, you have a couple of options:
1 - Calling the code for the click event;
Call cmdButton_Click
But you will have change the _Click routine from Private (default) to Public
so it can be seen outside the module.
Also reference the correct WB/WS as required.

2 - Some people feel it is wrong to call events like the above. If so use
cmdButton.Value=True

NickHK

wrote in message
oups.com...

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how to
execute the button.

Run or Call don't work.

Help.

TIA.



NickHK

How do I code VBA to hit button on a different worksheet?
 
Here's one way

ThisWorkbook.Worksheets("Sheet3").CommandButton4.V alue = True

NickHK

wrote in message
ups.com...

Yes, I am trying to fake a button click. The worksheet (there are many
worksheets, otherwise I would just click the button myself) is
protected so I can't change the code.

How do I go about doing #2? Would that fake a click?

Thanks.

NickHK wrote:
If you are trying to fake a button click, rather than Dave's suggestion

of
code location, you have a couple of options:
1 - Calling the code for the click event;
Call cmdButton_Click
But you will have change the _Click routine from Private (default) to

Public
so it can be seen outside the module.
Also reference the correct WB/WS as required.

2 - Some people feel it is wrong to call events like the above. If so

use
cmdButton.Value=True

NickHK

wrote in message
oups.com...

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how

to
execute the button.

Run or Call don't work.

Help.

TIA.





[email protected]

How do I code VBA to hit button on a different worksheet?
 
This works perfectly.

Thanks!


NickHK wrote:
Here's one way

ThisWorkbook.Worksheets("Sheet3").CommandButton4.V alue = True

NickHK

wrote in message
ups.com...

Yes, I am trying to fake a button click. The worksheet (there are many
worksheets, otherwise I would just click the button myself) is
protected so I can't change the code.

How do I go about doing #2? Would that fake a click?

Thanks.

NickHK wrote:
If you are trying to fake a button click, rather than Dave's suggestion

of
code location, you have a couple of options:
1 - Calling the code for the click event;
Call cmdButton_Click
But you will have change the _Click routine from Private (default) to

Public
so it can be seen outside the module.
Also reference the correct WB/WS as required.

2 - Some people feel it is wrong to call events like the above. If so

use
cmdButton.Value=True

NickHK

wrote in message
oups.com...

I have a protected worksheet that has a button that I want to execute
using VBA.

The worksheet in question is protected with the exception of certain
cells where I can paste values.

I am creating a VBA to do all the pasting but I can't figure out how

to
execute the button.

Run or Call don't work.

Help.

TIA.





All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com