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.
I would like to be able to call/execute the function based on the name of the workbook. Something similar to the function below:
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
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | WrkBk | Function | ||||
2 | Report1 | FmtRpt1 | ||||
3 | Report2 | FmtRpt2 | ||||
4 | Report3 | FmtRpt1 | ||||
5 | TblMstr | FmtTblMstr | ||||
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