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
| For i As Integer = 0 To nbfichier - 1
Dim nomfichier As String
nomfichier = ListBox1.Items(i).ToString
Label2.Text = nomfichier
Dim appExcel As Object 'Application Excel
Dim wbExcel As Object 'Classeur Excel
Dim wsExcel As Object 'Feuille Excel
'Ouverture de l'application
appExcel = CreateObject("Excel.Application")
'Ouverture d'un fichier Excel
wbExcel = appExcel.Workbooks.Open("\\mbn-file-001\Public\VerifScan\Fichier à importer\" + nomfichier)
'wsExcel correspond à la première feuille du fichier
wsExcel = wbExcel.Worksheets(1)
appExcel.Sheets(1).Columns("A:A").select
appExcel.Sheets(1).Columns("A:A").activate
appExcel.Sheets(1).Columns("A:A").delete
appExcel.Sheets(1).Columns("D:D").select
appExcel.Sheets(1).Columns("D:D").activate
appExcel.Sheets(1).Columns("D:D").delete
appExcel.sheets(1).rows("1:9").select
appExcel.sheets(1).rows("1:9").activate
appExcel.sheets(1).rows("1:9").delete
ListBox1.Items.Add("-----------------------------------------------------------")
ListBox1.Items.Add("Fichier " + nomfichier + " nettoyé")
Dim pos As Integer = nomfichier.LastIndexOf(".")
wsExcel.SaveAs("\\mbn-file-001\Public\VerifScan\Fichier à importer\" + nomfichier.Substring(0, pos) + "_nettoyé.xls")
ListBox1.Items.Add("-----------------------------------------------------------")
ListBox1.Items.Add("Fichier " + nomfichier + " sauvegardé")
'IO.File.Move("\\mbn-file-001\Public\VerifScan\Fichier à importer\" + nomfichier, "\\mbn-file-001\Public\VerifScan\Fichiers traités\" + nomfichier)
wsExcel = Nothing
wbExcel = Nothing
appExcel = Nothing
Next |
Partager