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

Creating a new Excel file from an existing Excel Sheet using VB Script

Status
Not open for further replies.

david081

Programmer
Jul 3, 2011
1
US

Hi.
Can someone help me with this script?
Why it doesn't run?
Thanks in advanced


<html>
<head>
</head>
<body>
<script type="text/vbscript">

‘Creating a new Excel file from an existing Excel Sheet

Function CopySheet (SourceFile, SheetName, DestinationFile)

Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
objExcel.DisplayAlerts = True

Set objWorkbook1= objExcel.Workbooks.Open(c:\SourceFile.xlsm)
Set objWorkbook2= objExcel.Workbooks.Add()

objWorkbook1.Worksheets(SheetName).UsedRange.Copy
objWorkbook2.Worksheets(“Sheet1).Range(“A1).PasteSpecial Paste =xlValues
objWorkbook2.Worksheets(“Sheet1).Name = ”Global”
objWorkbook2.saveAs(c:\DestinationFile.xlsm)
objWorkbook1.close
objWorkbook2.close
set objExcel=nothing

End Function



</script>
</body>
</html>
 
You've defined the function but you aren't calling it.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top