ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Worksheets.Copy in VBS??? (https://www.excelbanter.com/excel-programming/273196-excel-worksheets-copy-vbs.html)

Mark[_13_]

Excel Worksheets.Copy in VBS???
 
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

Peter Atherton

Excel Worksheets.Copy in VBS???
 
Mark

This is not what you asked for but it might be suitable.

Sub CopyTable()
Set Table = Worksheets(2).Range("A3:D7")
Table.Copy Destination:=Worksheets(3).Range("a3")
With Worksheets(3)
Cells(1, 1).Select
Selection.ColumnWidth = 6
Range("B1:D1").Select
Selection.ColumnWidth = 5
Range("A1").Select
End With
End Sub

Copying preserves the data and format. The Column widths
and row heights need to be done separately.

Regards
Peter
-----Original Message-----
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
.



All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com