Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cscript C:TestMyScript.vbs \C:TestSample.CSV \C:TestSample.xlsx
- srccsvfile = Wscript.Arguments(0)
- tgtxlsfile = Wscript.Arguments(1)
- 'Create Spreadsheet
- 'Look for an existing Excel instance.
- On Error Resume Next ' Turn on the error handling flag
- Set objExcel = GetObject(, "Excel.Application")
- 'If not found, create a new instance.
- If Err.Number = 429 Then '> 0
- Set objExcel = CreateObject("Excel.Application")
- End If
- objExcel.Visible = False
- objExcel.DisplayAlerts = False
- 'Import CSV into Spreadsheet
- Set objWorkbook = objExcel.Workbooks.Open(srccsvfile)
- Set objWorksheet1 = objWorkbook.Worksheets(1)
- 'Adjust width of columns
- Set objRange = objWorksheet1.UsedRange
- objRange.EntireColumn.Autofit()
- 'This code could be used to AutoFit a select number of columns
- 'For intColumns = 1 To 17
- ' objExcel.Columns(intColumns).AutoFit()
- 'Next
- 'Make Headings Bold
- objExcel.Rows(1).Font.Bold = True
- 'Freeze header row
- With objExcel.ActiveWindow
- .SplitColumn = 0
- .SplitRow = 1
- End With
- objExcel.ActiveWindow.FreezePanes = True
- 'Add Data Filters to Heading Row
- objExcel.Rows(1).AutoFilter
- 'set header row gray
- objExcel.Rows(1).Interior.ColorIndex = 15
- '-0.249977111117893
- aList=Array("NOT ", "NO ", "NONE", "!")
- For each item in aList
- For Each c In objWorksheet1.UsedRange
- If InStr(1, c.Value, item) > 0 Then
- c.Interior.ColorIndex = 6
- End If
- Next
- next
- 'Save Spreadsheet, 51 = Excel 2007-2010
- objWorksheet1.SaveAs tgtxlsfile, 51
- 'Release Lock on Spreadsheet
- objExcel.Quit()
- Set objWorksheet1 = Nothing
- Set objWorkbook = Nothing
- Set objExcel = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement