Hi,
Can I call a funtion or procedure..if the function or procedure name is stored in a variable..
[VBA]
Dim strg_var as string
strg_var = "Name_of_prc_to_call"
call strg_var
[/VBA]
thanks,
asingh
Printable View
Hi,
Can I call a funtion or procedure..if the function or procedure name is stored in a variable..
[VBA]
Dim strg_var as string
strg_var = "Name_of_prc_to_call"
call strg_var
[/VBA]
thanks,
asingh
For most Office product you can use "Run".
[VBA]Option Explicit
Public Sub ExampleOne()
Dim strSubName As String
strSubName = "SomeSpecialSub"
Run strSubName, "I only work in Excel."
End Sub
Public Sub SomeSpecialSub(messageText As String)
MsgBox messageText, Title:="It worked!"
End Sub[/VBA]
Note: This is not part of core VBA dll, but a function that is in the Excel Object model and also in Access, Word, Etc. For the most part the syntax and functionality is the same. But if you copy code (such as the snippet below) from, say, Excel to Access you will be running Excel.Application.Run and Access.Application.Run respectively not VBA.Run. And it is technically possible to run across a product that has implemented VBA but not the Run method in which case you will need to adapt your code. But for the most part you should be fine. If you really want to use the VBA library you can use call by name, but you can only call methods that reside in class modules, not standard modules, which could in turn force you to restructure your code.
Perfect..this will work for me..thanks a lot.
regards,
asingh
hth:)