1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Imports System
Public Module modmain
Sub Main()
Dim excelfile As String, csvfile As String
Dim args() As String = Environment.GetCommandLineArgs()
' Dim appPath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
Dim appPath As String = System.AppDomain.CurrentDomain.BaseDirectory()
excelfile = appPath & args(1)
csvfile = excelfile.Substring(0, excelfile.IndexOf(".")) & "_filtered.csv"
Dim xl As Object
xl = CreateObject("Excel.Application")
ExportToCsv (xl, excelfile, csvfile)
End Sub
Sub ExportToCsv(xl As Object, excelfile As String, csvfile As String)
xl.DisplayAlerts = False
xl.Workbooks.Open (excelfile)
xl.Worksheets(1).Activate
Dim firstcell As Object
firstcell = xl.Columns(2).Cells
Dim lastcell As Object
lastcell = xl.Columns(28).Cells
xl.Range(firstcell, lastcell).Copy
xl.Workbooks.Add
xl.Selection.PasteSpecial (-4163, -4142, False, False)
xl.Range(xl.Columns(3), xl.Columns(22)).Select()
xl.Selection.EntireColumn.Delete
xl.Range(xl.Columns(4), xl.Columns(5)).Select()
xl.Selection.EntireColumn.Delete
xl.Application.CutCopyMode = False
xl.ActiveWorkbook.SaveAs (csvfile,6,,,,,,,,,,True)
xl.ActiveWindow.Close
xl.Quit
End Sub
End Module |
Partager