Calling a function from a variable

davecarrr
davecarrr used Ask the Experts™
on
I am trying to call a function based on a variable passed from the calling function is there anyway to do this ??

e.g.

Private sub test1()
   test2(test3)
end sub

Private sub test2(var)
   call var ?????
end sub

Private sub text3()
   msgbox("Hello")
end sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
if the function is public, then use the CallByName :

CallByName me, var, vbMethod

CHeers
Senior .Net Consultant
Top Expert 2016
Commented:
You may try to use CallByName. Notice that test3 must be Public.

Private Sub Command1_Click()
    test2 "test3"
End Sub

Private Sub test2(var)
  CallByName Me, var, VbMethod
End Sub

Public Sub test3()
  MsgBox ("Hello")
End Sub

Author

Commented:
cheers emoreau after a little fiddling that worked brilliantly!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial