另個參考:
Sub TEST()
Dim xFile, T$, TR, xR As Range, Arr(), Brr, xL$, N&, i&, j&
xFile = Application.GetOpenFilename("(*.txt), *.txt")
If xFile = "" Then Exit Sub
For Each xR In Range([設定!A2], [設定!A1].Cells(Rows.Count, 1).End(xlUp))
If xR <> "" Then T = T & "|" & xR
Next
Open xFile For Input Access Read As #1
Do Until EOF(1)
Line Input #1, xL
TR = Split(xL, vbTab)
If InStr(T & "|", "|" & TR(4) & "|") Then
N = N + 1: ReDim Preserve Arr(N - 1): Arr(N - 1) = TR
End If
Loop
Close #1
If N = 0 Then Exit Sub
ReDim Brr(N - 1, 6)
For i = 0 To N - 1
For j = 0 To UBound(Arr(i))
Brr(i, j) = Arr(i)(j)
Next
Next
Set xR = [資料!A1].Cells(Rows.Count, 1).End(xlUp)
If xR <> "" Then Set xR = xR(2)
xR.Resize(N, 7) = Brr
End Sub