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?
LVL 43
Saqib Husain, SyedEngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zorvek (Kevin Jones)ConsultantCommented:
Creating a copy of the master workbook is a commonly used technique. I've used it a few times.

There are two methods:

Save a copy of the workbook and delete what you don't want.

Create a new workbook and copy what you do want.

Place the code that you want in the copy workbook in separate code modules and only copy those modules. Same with user forms.

I can provide code to copy code modules and user forms.

Kevin
0
zorvek (Kevin Jones)ConsultantCommented:
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
0
Saqib Husain, SyedEngineerAuthor Commented:
I think I have got it....Create a separate file which contains all the macros and modules required and let the master file change the data in that "separate" file and save it for the individual.

Thanks for your suggestions which gave me this idea. Will close the question when I have done and tested the application.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Saqib Husain, SyedEngineerAuthor Commented:
This method avoids accessing code through code
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.