Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. cscript C:TestMyScript.vbs \C:TestSample.CSV \C:TestSample.xlsx
  2.  
  3. srccsvfile = Wscript.Arguments(0)
  4. tgtxlsfile = Wscript.Arguments(1)
  5.  
  6. 'Create Spreadsheet
  7. 'Look for an existing Excel instance.
  8. On Error Resume Next ' Turn on the error handling flag
  9. Set objExcel = GetObject(, "Excel.Application")
  10. 'If not found, create a new instance.
  11. If Err.Number = 429 Then '> 0
  12. Set objExcel = CreateObject("Excel.Application")
  13. End If
  14.  
  15. objExcel.Visible = False
  16. objExcel.DisplayAlerts = False
  17.  
  18. 'Import CSV into Spreadsheet
  19. Set objWorkbook = objExcel.Workbooks.Open(srccsvfile)
  20. Set objWorksheet1 = objWorkbook.Worksheets(1)
  21.  
  22. 'Adjust width of columns
  23. Set objRange = objWorksheet1.UsedRange
  24. objRange.EntireColumn.Autofit()
  25. 'This code could be used to AutoFit a select number of columns
  26. 'For intColumns = 1 To 17
  27. ' objExcel.Columns(intColumns).AutoFit()
  28. 'Next
  29.  
  30. 'Make Headings Bold
  31. objExcel.Rows(1).Font.Bold = True
  32.  
  33. 'Freeze header row
  34. With objExcel.ActiveWindow
  35. .SplitColumn = 0
  36. .SplitRow = 1
  37. End With
  38. objExcel.ActiveWindow.FreezePanes = True
  39.  
  40. 'Add Data Filters to Heading Row
  41. objExcel.Rows(1).AutoFilter
  42.  
  43. 'set header row gray
  44. objExcel.Rows(1).Interior.ColorIndex = 15
  45. '-0.249977111117893
  46. aList=Array("NOT ", "NO ", "NONE", "!")
  47. For each item in aList
  48. For Each c In objWorksheet1.UsedRange
  49. If InStr(1, c.Value, item) > 0 Then
  50. c.Interior.ColorIndex = 6
  51. End If
  52. Next
  53. next
  54.  
  55.  
  56. 'Save Spreadsheet, 51 = Excel 2007-2010
  57. objWorksheet1.SaveAs tgtxlsfile, 51
  58.  
  59. 'Release Lock on Spreadsheet
  60. objExcel.Quit()
  61. Set objWorksheet1 = Nothing
  62. Set objWorkbook = Nothing
  63. Set objExcel = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement