Sub OpenTextFileTest()
Const ForReading = 1, ForWriting = 2, ForAppending = 3, maxLine = 100
Dim fs, f, aKQ() As String, iL As Long
Dim FD As FileDialog
Dim FFs As FileDialogFilters
Dim strFileName As String, sKQ As String
On Error GoTo Problem
Set FD = Application.FileDialog(msoFileDialogOpen)
With FD
Set FFs = .Filters
With FFs
.Clear
.Add "TXT", "*.txt"
End With
If .Show = False Then Exit Sub
strFileName = .SelectedItems(1)
End With
Set FD = Nothing
Set FFs = Nothing
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(strFileName, ForReading)
ReDim aKQ(1 To maxLine, 1 To 1)
With f
iL = 0
While (Not .AtEndOfStream) And (iL < maxLine)
iL = iL + 1
aKQ(iL, 1) = .ReadLine
sKQ = sKQ & "|" & aKQ(iL, 1)
Wend
.Close
End With
ActiveSheet.Range("A1").Resize(maxLine, 1) = aKQ
Set f = Nothing
Set fs = Nothing
Exit Sub
Problem:
MsgBox "You have not selected a valid txt-file."
End Sub