Bonjour a tous,
Mon probleme est assez simple, je souhaiterai importer un fichier .csv d'un dossier et le mettre a chaque fois sur la meme feuille nommé data.
Cependant le fichier .csv n'a pas toujours le meme nom! donc obligation d'utiliser la fonction : Application.GetOpenFilename("csv Files (*.csv), *.csv") .
Voici ce que j'ai fait:Il bug et me met en rouge ce que j'ai mis en rouge...Quelqu'un peut m'aider?merci!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
39
40
41
42
43
44
45 Sub Weekly() Dim f As Variant f = Application.GetOpenFilename("csv Files (*.csv), *.csv") If f = False Then Exit Sub With Worksheets("Data").QueryTables.Add(Connection:= _ "TEXT;" & f, Destination _ :=Range("$A$1")) .Name = "fichier_client" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 1252 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1) .TextFileTrailingMinusNumbers = True .Refresh BackgroundQuery:=False End With Rows("1:1").Select Selection.Font.Bold = True Columns("A:A").Select Range(Selection, Selection.End(xlToRight)).Select Columns("A:AM").EntireColumn.AutoFit End Sub
Partager