Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Multiple Worksheets based on a Template

Status
Not open for further replies.

picu

Programmer
Feb 28, 2002
5
US
'Create the Excel Object
Set xlApp = Server.CreateObject("Excel.Application")

'Getting the Template from server
Set xlWb = xlApp.Workbooks.Add (Server.MapPath ("/folderPath/Template1.xlt"))

'Create new worksheets but after 3 I need other
'worksheets with the template from the server

if wSheet > 3 then
xlApp.Workbooks.Add
end if


I need to add more worksheets based on Template1.xlt (which has 3 worksheets, thus when wSheet greater than 3 I need to add extra worksheets. I NEED EXTRA WORKSHEETS BASED ON THE Template.xlt. How do I do this?



 
Hi, picu,

So ALL the worksheets in Template1.xlt are identical?

If so then assign an object to one of these sheets and use it to propogate sheets.

Or am I missing something? Skip,
metzgsk@voughtaircraft.com
 
I wrote some code that seems to work...
Code:
Sub CreateFromxlt()
    Dim sht1 As Worksheet, sht2 As Worksheet, sht3 As Worksheet
    Set sht1 = Workbooks("Book2.xlt").Worksheets(1)
    Set sht2 = Workbooks("Book2.xlt").Worksheets(2)
    Set sht3 = Workbooks("Book2.xlt").Worksheets(3)
    
    With ActiveWorkbook
        sht3.Copy Before:=Workbooks("Book3").Sheets(1)
    End With
End Sub
VOLA! :) Skip,
metzgsk@voughtaircraft.com
 
Hi SkipVought,

Thanks for the quick response.

Yes, all worksheets in Template1.xlt are the same.

How do I assign the object to one of the Template1.xlt sheets to propagate sheets? Please, provide code.

If you need more code/info, please let me know.

Thanks,

Picu
 
Skip,

Great!

I am creating 1 workbook with multiple worksheets.

Multiple worksheets are created dynamically depending on the end user's selection.

In summary, 1 excel application, 1 workbook and x number of worksheets based on x number of selected items from the end user. Also, I am doing this in ASP/VBScript. Not from VBA or excel programming.

Please, provide any code as above. Thanks.


 
picu,

There may be some in this forum that program in those languages. I do not.

You may get better results posting your question in a more topic-appropriate forum.

Good luck! :) Skip,
metzgsk@voughtaircraft.com
 
Eventhough, I may be using asp/vbscript, I am using the same VBA Coding Techniques to create the Excel Application Object, the Workbooks + Worksheets. I need the vba resources, that is why I am in this forum.

I need to create multiple worksheets with a template background (xlt file). How do I do that? Please, add any code. Thanks.



 
If all the sheets are to be the same, can you copy the first the required number of times. The following code will copy sheet 1 x number of times.
Code:
    For i = 1 To x
        y = ActiveWorkbook.Sheets.Count
        Sheets(1).Copy After:=Sheets(y)
        Sheets(y+1).Name = "Sheet" & y + 1
    Next i
AC

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top