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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Worksheets.Copy in VBS??? 1

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hello,
I've been racking my brain and searching for references to figure out how to copy and excel work sheet with in a single work book to use as a template with in that same work book. The only thing I can find is VBA code, I'm doing an administration script in VBS and can't figure out how to convert it.

According to Microsoft's reference the VBA command is:
Worksheets("Sheet1").Copy after := Worksheets("Sheet3")

I've got the VBS code below.

Set objExcel = WScript.CreateObject("EXCEL.application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Worksheets.Add.Name ="USERSLIST"


This part of it objExcel.Worksheets("Sheet1").Copy will copy the worksheet but to a new workbook. 8/

Any help at all on this would be greatly appreciated.

Thanks in advance
 
I found the answer and wanted to post it incase anybody else needed it


Set ws = objExcel.Worksheets
ws("USERSLIST").Copy ,ws(2)


Thanks
 
Though the copy method work, the "template" may worker more transparent. Open the default .xls and save as .xlt. Next time you use menu "File"-"New", the template file show up in the New dialog, click it and open, you will get a new file will all the sheets, values, formating, etc, embedded in the new worksheet.

I had some experience in using template in Word, wonderful. The hard part is in distribution, that is another thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top