ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do you trigger an "On Click" event programatically (https://www.excelbanter.com/excel-programming/413058-how-do-you-trigger-click-event-programatically.html)

Rob Wills

How do you trigger an "On Click" event programatically
 
I have a spreadsheet - which is locked - in which I need to click a button to
trigger a process.

However I wish to add this to a scheduler, so that this is triggered
automatically.

I can use the following to identify and select the shape
====================
Sub Shape_Names()
Dim wks As Worksheet
Dim shp As Shape

Set wks = ActiveSheet

For Each shp In wks.Shapes
debug.print shp.Name
shp.select
Next shp

End Sub
======================

but this does not trigger the on click event.

Any Ideas?

Thanks
Rob

Jim Thomlinson

How do you trigger an "On Click" event programatically
 
Shapes do not have events associated with them. They have macros that are
assigned to them. Why not just run the macros that are assigned to the shapes?
--
HTH...

Jim Thomlinson


"Rob Wills" wrote:

I have a spreadsheet - which is locked - in which I need to click a button to
trigger a process.

However I wish to add this to a scheduler, so that this is triggered
automatically.

I can use the following to identify and select the shape
====================
Sub Shape_Names()
Dim wks As Worksheet
Dim shp As Shape

Set wks = ActiveSheet

For Each shp In wks.Shapes
debug.print shp.Name
shp.select
Next shp

End Sub
======================

but this does not trigger the on click event.

Any Ideas?

Thanks
Rob


Christian Treffler

How do you trigger an "On Click" event programatically
 
Rob Wills schrieb:

I have a spreadsheet - which is locked - in which I need to click a button to
trigger a process.

However I wish to add this to a scheduler, so that this is triggered
automatically.


I don't think that you have a chance to trigger an event. The easiest
way to solve this, is the following:

- Put the whole code which runs in the 'Btn_Click' subroutine
in a seperate subroutine. Call this subroutine from the
'Btn_Click' subroutine.
- You can call this subroutine now from every other subroutine instead
of triggering a click event on the button.

HTH,
Christian

Rob Wills

How do you trigger an "On Click" event programatically
 


"Christian Treffler" wrote:


- Put the whole code which runs in the 'Btn_Click' subroutine
in a seperate subroutine. Call this subroutine from the
'Btn_Click' subroutine.
- You can call this subroutine now from every other subroutine instead
of triggering a click event on the button.

HTH,
Christian


=======================================
Apologies - I didn't make it clear.
The spreadsheet is locked - hence I can't get to the code which is assigned
to the commandbutton...

I was hoping to select the object and then use sendkeys or something similar
- but I haven't managed to figure it out yet....

Cheers
Rob

Jim Thomlinson

How do you trigger an "On Click" event programatically
 
Note... Sendkeys is not very reliable. You should avoid it where you can. I
personally never use sendkeys.

Why can you not access your macros. Is the project locked or is the workbook
locked or is are the sheets locked? Protection of the book or sheets has
nothing to do with you ability to call macros. The macros might fail if your
sheets are protected but the code will attempt to execute. If it is a matter
of the macros failing just remove the protection from the sheets at the start
of execution and reprotect the sheets as the macro completes.

--
HTH...

Jim Thomlinson


"Rob Wills" wrote:



"Christian Treffler" wrote:


- Put the whole code which runs in the 'Btn_Click' subroutine
in a seperate subroutine. Call this subroutine from the
'Btn_Click' subroutine.
- You can call this subroutine now from every other subroutine instead
of triggering a click event on the button.

HTH,
Christian


=======================================
Apologies - I didn't make it clear.
The spreadsheet is locked - hence I can't get to the code which is assigned
to the commandbutton...

I was hoping to select the object and then use sendkeys or something similar
- but I haven't managed to figure it out yet....

Cheers
Rob


Tim Williams

How do you trigger an "On Click" event programatically
 
When you say "locked" are you implying that this code is in a 3rd party
workbook ?

What kind of button is it you're trying to click ?
- shape with "onaction" macro
- forms button
- control toolbox button
?

Tim


"Rob Wills" wrote in message
...


"Christian Treffler" wrote:


- Put the whole code which runs in the 'Btn_Click' subroutine
in a seperate subroutine. Call this subroutine from the
'Btn_Click' subroutine.
- You can call this subroutine now from every other subroutine instead
of triggering a click event on the button.

HTH,
Christian


=======================================
Apologies - I didn't make it clear.
The spreadsheet is locked - hence I can't get to the code which is
assigned
to the commandbutton...

I was hoping to select the object and then use sendkeys or something
similar
- but I haven't managed to figure it out yet....

Cheers
Rob





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

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