Bonjour à toutes et tous,
Ainsi une nouvelle source de données (dont l'extension est en .csv) à mettre en perspectives avec d'autres, je souhaite importer dans un workbook existant à certaines worksheets ces données.
la routine proposée pour effectuer ce processus est la suivante:
En l'état, la routine execute correctement les premières boucles "if", "for", "if". Par contre l’exécution des commandes inclues dans la boucle "with", si elles ne font pas échouer l'exécution de la routine, ne se traduisent par aucune importation de données.
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
46
47
48
49 Sub Test1() ' Const MyExt = "TEXT;" Const MyPath = "----loading path----/" ' Dim MyName1 As String Dim MyName2 As String Dim n As Integer ' n = ThisWorkbook.Worksheets.Count ' MyName1 = Dir(MyPath & "*.csv") ' If MyName1 = "" Then MsgBox "No files found" ' For i = 1 To n ThisWorkbook.Worksheets(i).Activate MyName2 = ThisWorkbook.Worksheets(i).Name ' If Mid(MyName2, 3, 1) = "2" Then With ActiveSheet.QueryTables.Add(Connection:=MyExt & MyName1, Destination:=Range("$H$9")) .Name = "" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .TextFilePromptOnRefresh = False .TextFilePlatform = 850 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = True .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1) .TextFileDecimalSeparator = "." .TextFileTrailingMinusNumbers = True End With End If Next End Sub
Auriez vous quelques conseils, ou solutions?
Bien cordialement,
Partager