VBA -- procedures as arguments?

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
 
C

Chip Pearson

Dave,

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

Application.Run ProcName

i
 

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

Top