Bartjuh1990
Gebruiker
- Lid geworden
- 16 jan 2008
- Berichten
- 10
Ik heb 200 textbestanden ingeladen via een macro in excel, enkel moet hier nog een filename bij voor de duidelijkheid. Wat moet ik toevoegen om op de eerste rij de bestandsnaam (zonder .txt) te krijgen.
Volgens mij is het simpel, alleen ik kom er niet snel uit.
Code:
Sub LoadPipeDelimitedFiles()
Dim idx As Integer
Dim fpath As String
Dim fname As String
idx = 0
fpath = "C:\Users\Bart\Dropbox\1 TUE\Master\Semester B\M1\Frisse scholen\3. Simulation\Results\results\"
fname = Dir(fpath & "*.txt")
While (Len(fname) > 0)
idx = idx + 1
ActiveSheet.Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
& fpath & fname, Destination:=Range("A2"))
.Name = "a" & idx
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileDecimalSeparator = "."
.TextFileThousandsSeparator = " "
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
fname = Dir
End With
Wend
End Sub
Volgens mij is het simpel, alleen ik kom er niet snel uit.