'Resize and SaveAs Excel 'Takes a delimited text file, resizes columns, and saves as Excel 'overwrites if same name 'Alan dot kaplan at va dot gov, www.akaplan.com/blog '6-16-2007 Option Explicit Dim strFileName If WScript.Arguments.Count = 1 Then strFileName = WScript.Arguments(0) Else strFileName = InputBox("Convert What Text File to Excel?","File Name") End If SaveAsExcel strFileName Sub SaveAsExcel(strFileName) Const xlnormal = -4143 dim fso, oXL, objRange Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FileExists(strFileName) Then WScript.Quit Set oXL = CreateObject("Excel.Application") 'oXL.Visible = True oXL.DisplayAlerts=False ' don't display overwrite prompt. oXL.Workbooks.Open(strFileName) Set objRange = oXL.Worksheets(1).UsedRange objRange.EntireColumn.Autofit() oXL.ActiveWorkBook.SaveAs strFileName,xlnormal,,,,,,,True 'overwrite existing oXL.ActiveWorkBook.Close oXL.Quit 'WScript.Echo "Done" End Sub