VBA -- procedures as arguments?

  • Thread starter Thread starter Dave Ring
  • Start date Start date
D

Dave Ring

I would like to pass a VBA subroutine as an argument to another VBA
subroutine. If I pass the name of the variable subroutine as a string
and execute it using a Run statement in the host subroutine, the result
is significantly slower than if I put a Select/Case statement in the
host subroutine that directly calls the variable subroutine. E.g., if
ProcName1 is a string containing the name of procedure NamedProc1, then

Sub HOSTSUB(ProcName As String)
Run ProcName
End Sub

is slower than

Sub HOSTSUB(ProcName As String)
Select Case ProcName
Case ProcName1
NamedProc1
End Select
End Sub

Is there a better way to handle variable procedures in VBA?

Dave Ring
 
Dave,

If you pass the procedure name as a string, you can use Application.Run to
execute it. E.g.,

Application.Run ProcName

i
 
Back
Top