hi everyone
i have some code wriiten for before update event and change event
is it possible to call on these procedures either via another event or code?
thanks
hi everyone
i have some code wriiten for before update event and change event
is it possible to call on these procedures either via another event or code?
thanks
If you want to call the same code from multiple events, the best way is to put the code into a separate routine and call that routine from all required events. You can also call event procedures the same way you call other private procedures.
Regards,
Rory
Microsoft MVP - Excel
thanks rory
tried to call the change procedure using the following code
application.run "'RingGaugeNew.xls'!Grade_Change"
but this comes up with a an error saying the macro cant be found
just checking it again to ensure i have typed it in correctly
thanks
As I said, the best way is to put the code into a separate routine.
What is 'Grade' and where are you trying to call the procedure from? Event procedures belong to objects, so if for example Grade is a combobox on a worksheet, you would need to use syntax like:
[VBA]Application.Run "workbook.xls!sheet1.Grade_Change"[/VBA]
Regards,
Rory
Microsoft MVP - Excel
so for a form i would change sheet1 to the form name
thanks
northernstar
Why would you want to call these event procedures?
You can't call a procedure in a form unless it is loaded, AFAIK.
Regards,
Rory
Microsoft MVP - Excel
rory
I don't think that's actually the case, but I wonder why you would want to call them in the first place.
Create a userform, add a button and give this a shot in a standard module.
[vba]
UserForm1.CommandButton1.Value = True
[/vba]
Or you could even remove Private from the event sub header and use this.
[vba]
Call UserForm1.CommandButton_Click
[/vba]
The command button will still work but I don't know if there are any implications. eg scope, visbility etc
Yes, you can do that, but you are implicitly loading the userform the minute you refer to it. Using Application.Run won't work because you don't load the userform that way.
Regards,
Rory
Microsoft MVP - Excel
rory
Never realised that.
Just knew you could call the events like that.
I'd still like to know why the OP wants to do it anyway.
I can imagine why you might want the same code called; I can't see why you wouldn't just put the relevant code into its own routine, where it belongs...
Regards,
Rory
Microsoft MVP - Excel
rory
Perhaps the OP could utilize a class module?
Hard to tell without more information. eg what the code does, what controls etc
I can't recall which, if any controls, would have those events exposed in a class module.
here is the file which i am working on
seem to have got round the problem
but also seem to have a lot of repeating codes
i know my programming skills are not very good, but i am self taught and dont always follow good practise but get the result i need
the form and programming is not finished yet
i would appreciate your comments and advice, thanks
any questions please let me know