PDA

View Full Version : How to dynamically place a VBA code to a Output excel file?



pivotguy
01-07-2016, 06:02 AM
The VBA code creates multiple files from input file. I would like to dynamically place a VBA code in each output file.

When "input.xlsm" (attached) code executes , it creates (a) Craig Smith.xls (2 tabs - Summary and detail) (b) Kelly Davis.xls (2 Tabs-Summary and detail) . The end product should look like "1Kelly Davis.xlsm" and "1Craig Smith.xlsm" . I place the code under "summary" module in "1Kelly Davis.xlsm" and "1Craig Smith.xlsm" files.

Any suggestion.

GTO
01-08-2016, 08:06 AM
Hi there,

Rather than creating a new workbook and adding code to one of the sheet modules, you would likely find it easier to simply add a sheet to the source workbook. Then add the code to this "template" sheet's module. You can then create a new workbook by copying the sheet to a new workbook and you already have the code in it.

Hope that helps,

Mark

snb
01-09-2016, 05:31 AM
Did you consider


Sub M_snb()
if Thisworkbook.name= "input.xlsm" then thisworkbook.savecopyas "G:\OF\1Craig Smith.xlsm"
End sub