creating workbooks(with macros and userforms) programmatically

  • Thread starter Thread starter amitkr
  • Start date Start date
A

amitkr

hi
I ve a template(.xlt) file.The file contains some macros and a use
form.When I open the xlt file i get the user form..

In some other workbook I ve written code to create new workbooks usin
the above mentioned template file as the template...

Though my code creates the new workbook but that workbook does not hav
the user form...

I want the userform to be available in each workbook I create...

Any one help pleas
 
I tried and gave up.

Why don't you instead start with a copy of a workbook that is empt
except for the VBA modules and form(s) and just make copies of tha
workbook?

It might not be as elegant as what you are doing, but it would be a lo
simpler
 
I put a userform in a new workbook. I put a button on a worksheet in that
workbook that showed the userform.

I saved that workbook as a template (and closed it).

Then in another workbook, I put this code:

Option Explicit
Sub testme()
Dim newWkbk As Workbook
Set newWkbk = Workbooks.Add(template:="c:\my documents\excel\book1.xlt")
End Sub

The new workbook based on this template had the userform and even worked when I
clicked on it.

If you're asking why the userform doesn't show when you create the new workbook,
try putting the code to show the userform in the Workbook_open event.

Or run the auto_open code in your code.

Option Explicit
Sub testme()
Dim newWkbk As Workbook
Set newWkbk = Workbooks.Add(template:="c:\my documents\excel\book1.xlt")
newWkbk.RunAutoMacros which:=xlAutoOpen
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top