How to achieve "Call MyVarWithProcNameInIt"?

  • Thread starter Thread starter count
  • Start date Start date
C

count

How to make Call statement to accept procedure names by reference.
Useful as it may be, its immediate purpose is to be able to shorten coding
and say, for example:

Call Frame1.ActiveControl.Name & "_Click"

Purpose is to fire up OptionButton_Click routine within form, when we come
back from another form.
TIA
Paul
 
Paul,

I thought of trying Application.Run, but as expected, it wouldn't run an
event procedure. My tests were with commandbuttons. What I then did was to
create a macro in a standard module that ran the commandbutton_click event,
and I named it Commandbutton1_Run, and in my form code I fired that.

So my macro was

Sub CommandButton1_Run()
UserForm1.CommandButton1_Click
End Sub

and my form code was

Application.Run "Commandbutton1_Run".

So maybe if you have a macro

Sub OptionButton1_Run()
UserForm1.Frame1.OptionButton1_Click
End Sub

and in the form have

Application.Run ActiveControl.Name & "_Run"

It's a bit kludge, ads you will need a macro for each event that it could
run, but it might work for you.


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob,
Thanks, it works using Application.Run "NameOfProcDeclAtModuleLevel"
So it is now a matter of efficiency I need to assess :)
I need to mirror all Private OptionButtonXX_Click procedures of a form at
Module level.
XX is up to 18 so it's gonna be tedious and I'd have to remember of
mirroring all possible changes.
But surely the code is clean - thanks Bob.
Paul
 
I'm wondering if CallByName is what you require:

This in the form code module (Userform1):

Public Sub OptionButton1_Click()
MsgBox "Hello"
End Sub

This anywhere in the project:

Sub test()
CallByName UserForm1, "OptionButton1_Click", VbMethod
End Sub
 
Yesss! You're a gem!
Was looking for that somwhere near Call - in Statements ... but this one is
in Functions indeed.
Thanks,
Paul
 

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

Back
Top