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
| Sub testquerytable2()
Dim fichier_choisi As Variant
fichier_choisi = Application.GetOpenFilename(FileFilter:=" txt file or Excel Files ( *.txt;*.xls*), ( *.txt*.xls*), All Files, *.*", FilterIndex:=1)
If fichier_choisi = False Then Exit Sub
If LCase(Mid(fichier_choisi, InStrRev(fichier_choisi, ".") + 1)) = "txt" Then
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & fichier_choisi, Destination:=Range("$A$1"))
.FieldNames = True
.PreserveFormatting = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileTabDelimiter = True
.TextFileColumnDataTypes = Array(4, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.Delete
End With
With ActiveSheet
tablo = .UsedRange.Value
.UsedRange.Clear
.Range("A:A").NumberFormat = "DD/MM/YYYY"
.Range("B:B").NumberFormat = "h:mm;@"
.Cells(1, 1).Resize(UBound(tablo), UBound(tablo, 2)).Value = tablo
End With
Else
' faire ce qu'il faut ici si c'est un "xls" ou xlsx,xlsm,xla,etc.....
End If
End Sub |
Partager