beckwiga
Programmer
- Mar 30, 2005
- 70
All-
Having some trouble. Trying to write a VBScript that will delete a worksheet from an Excel file. Sounds simple enough but I can't get this to work. I figured I would pass the xls name as arg1 and the worksheet name as arg2. Also, I don't want to be prompted since I am going to run this from a batch file. Any help would be MUCH appreciated. Thanks, beckwiga.
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim SourceDir, args, filename, worksheetname
Dim InFile, InSheet, DateFile, FileDate, Text, FileOut, Sheet
Dim objShell, objFolder, objFSO, strFileName, objArgs, objExcel, objWorkbook, objSheet
'On Error Resume Next
SourceDir = "F:\input\"
Set args = WScript.Arguments
filename = args(0)
worksheetname = args(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
InFile = SourceDir & filename
InSheet = worksheetname
Set objWorkbook = objExcel.Workbooks.Open (InFile)
objExcel.DisplayAlerts = False
objExcel.sheets(worksheetname).Delete
objExcel.DisplayAlerts = True
objWorkbook.Close
FileOut.Close
objExcel.Quit
Having some trouble. Trying to write a VBScript that will delete a worksheet from an Excel file. Sounds simple enough but I can't get this to work. I figured I would pass the xls name as arg1 and the worksheet name as arg2. Also, I don't want to be prompted since I am going to run this from a batch file. Any help would be MUCH appreciated. Thanks, beckwiga.
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim SourceDir, args, filename, worksheetname
Dim InFile, InSheet, DateFile, FileDate, Text, FileOut, Sheet
Dim objShell, objFolder, objFSO, strFileName, objArgs, objExcel, objWorkbook, objSheet
'On Error Resume Next
SourceDir = "F:\input\"
Set args = WScript.Arguments
filename = args(0)
worksheetname = args(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExcel = CreateObject("Excel.Application")
InFile = SourceDir & filename
InSheet = worksheetname
Set objWorkbook = objExcel.Workbooks.Open (InFile)
objExcel.DisplayAlerts = False
objExcel.sheets(worksheetname).Delete
objExcel.DisplayAlerts = True
objWorkbook.Close
FileOut.Close
objExcel.Quit