Private Sub Workbook_Open()
Call import_csv
End Sub
Option Explicit
Dim clas_csv As String
Public clas_trav As String
Public fls_trav As String
Public m_fichier As Variant
Sub import_csv()
Dim m_fichier As Variant
m_fichier = Application.GetOpenFilename('CSV Files (*.csv),*.csv', , 'Ouverture fichier Remonté de Caisse', , True)
Workbooks.Open Filename:=m_fichier
clas_csv = ActiveWorkbook.Name
Call trie_col_A
Call Ajout_entête_date
End Sub
Sub trie_col_A()
Selection.CurrentRegion.Select
Selection.Sort Key1:=Range('A1'), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End Sub
Public Sub Ajout_entête_date()
Dim strDate As Date
Dim strDateTemp As String
With ActiveWorkbook.Sheets(1)
.Rows('1:1').Insert Shift:=xlDown
.Cells(1, 1) = 'Produit'
.Cells(1, 2) = 'Quantité'
.Cells(1, 3) = 'Prix'
.Cells(1, 4) = 'Date'
strDateTemp = Right(.Name, 8)
strDate = CDate(Mid(strDateTemp, 1, 2) & '-' & Mid(strDateTemp, 3, 2) & '-' & Mid(strDateTemp, 5, 8))
.Range(.Cells(2, 4), .Cells(.Cells(65000, 1).End(xlUp).Row, 4)).Value = strDate
End With
End Sub