Execute Dynamically Named Function/Sub

tmurj

New Member
Joined
Jun 21, 2007
Messages
23
I have a list of workbooks and a related function/sub that formats the workbook and outputs some data. The list is stored in a sheet similar to the following.
Book1
ABCD
1WrkBkFunction
2Report1FmtRpt1
3Report2FmtRpt2
4Report3FmtRpt1
5TblMstrFmtTblMstr
Sheet1


I would like to be able to call/execute the function based on the name of the workbook. Something similar to the function below:

Code:
[color=darkblue]Sub[/color] RunTheFunc()
    [color=darkblue]Dim[/color] FuncName [color=darkblue]As[/color] [color=darkblue]String[/color], bResult [color=darkblue]As[/color] [color=darkblue]Boolean[/color]
    [color=green]'FuncNameList is a named range within the sheet[/color]
    FuncName = Application.WorksheetFunction.VLookup("Report1", "FuncNameList", 2, [color=darkblue]False[/color])
    [color=green]' this would set FuncName = "FmtRpt1" based on the example table[/color]
    [color=green]'---[/color]
    'I need to be able to execute the function FmtRpt1 with something like
    bResult = Exec(FuncName)
    [color=green]' or  --[/color]
    [color=darkblue]Call[/color] FuncName   'and have the code located in funcname actually execute to format the report
[color=darkblue]End[/color] [color=darkblue]Sub[/color]



This would allow my users to dynamically add new report workbooks without modification to my main app as long as the report uses a formatting program that already exists. The report workbooks are being output in the background and the main app runs thru a list of workbooks and dynamially formats them and consolidates the output.

Any ideas or input would be greatly appreciated. TIA :-)
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top