Importer données avec la commande With ActiveSheet.QueryTables.Add
Bonjour,
question d'accélérer une macro, j'ai enregistrer une macro d'importation de données et je veux l'adapter à mon fichier, mais ça plante à la troisième ligne...
Dans la macro enregistrer, c'était écrit quelque chose du genre
"TEXT;Y\dossiervba\doc3.log"
Moi je voudrais mettre une variable à la place de Y\dossiervba\doc3.log
Merci de m'aider!
Code:
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
|
emplacement_fichier=fichier.path
Workbooks(WB).Worksheets(nom_WS).Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & emplacement_fichier _
, Destination:=Range("A1"))
.Name = Mid(fichier.Name, 1, Len(fichier.Name) - 4)
.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 = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1)
.TextFileFixedColumnWidths = Array(17)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With |