V
VBA Coder
I would like to call a subroutine dynamically based on a string that I am
building. I cannot seem to get the syntax to work. I have a listbox with
over 100 items in it, and each item within the listbox calls it's own
subroutine. With a simple string variable, I'd like to read the value
selected from the listbox and call it's subroutine, which is the same name.
Some very simple sample code is below:
Old Code Method:
Select Case Me.listItemList.Text
Case "Sub1"
Sub1_Proc
Case "Sub2"
Sub2_Proc
Case "Sub3"
Sub3_Proc
Case "Sub4"
Sub4_Proc
etc...will continue up past 100 with the same logic
End Select
New Code:
I would like to just reference the listbox and append "_Proc" to the end and
then call that subroutine, something like below:
Dim sProc as string
sProc = Me.listItemList.Text & "_Proc"
Call sProc
building. I cannot seem to get the syntax to work. I have a listbox with
over 100 items in it, and each item within the listbox calls it's own
subroutine. With a simple string variable, I'd like to read the value
selected from the listbox and call it's subroutine, which is the same name.
Some very simple sample code is below:
Old Code Method:
Select Case Me.listItemList.Text
Case "Sub1"
Sub1_Proc
Case "Sub2"
Sub2_Proc
Case "Sub3"
Sub3_Proc
Case "Sub4"
Sub4_Proc
etc...will continue up past 100 with the same logic
End Select
New Code:
I would like to just reference the listbox and append "_Proc" to the end and
then call that subroutine, something like below:
Dim sProc as string
sProc = Me.listItemList.Text & "_Proc"
Call sProc