Link to home
Start Free TrialLog in
Avatar of Saqib Husain
Saqib HusainFlag for Pakistan

asked on

VBA - How to create a workbook containing workbook event handlers as well as userforms.

I have a workbook which generates blank monthly timesheets for individual employees. The employee selects the name, designation, month and year and clicks a button. This copies a blank timesheet worksheet (which contains macros in the worksheet module) to a new workbook. The new workbook is ready with the worksheet event handlers for the individual.

I now need to extend the capabilities of the workbook to have workbook event handlers and also userforms. I am not clear on how to use VBA to create such workbooks.

One way I can see is to use a macro to write the macros. But this means that every individual's computer should have this feature enabled. I do not think I can go with this.

Another way could be to copy the entire workbook to a new workbook (I am not sure how I would do that) and then delete the other sheets which are not supposed to be copied over. But then the workbook module would contain all the macros related to generating the new workbook in addition to the ones needed to use the timesheet.

Can someone guide me or suggest any other method to be able to copy the macros to a new workbook?
SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use the SaveAsCopy method to create a copy of the current workbook without changing the connection to the originally open workbook. The copy saved is closed.

   ThisWorkbook.SaveCopyAs "C:\Full\Path\To\File.xls"

Kevin
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Saqib Husain

ASKER

This method avoids accessing code through code