Sub 匯入文字檔()
Dim xFile, uFile, uHead As Range, Jm&, Km&, X, xT, xL
Range("A:A").Clear '清除舊匯入資料
'-----------------------------------------------------
Application.ScreenUpdating = False
Do
If xChk = 0 Then
xFile = Dir(ThisWorkbook.Path & "\*.txt")
If xFile = "" Then MsgBox "※找不到 TXT 檔案! ", 0 + 16: Exit Sub
xChk = 1
Else
xFile = Dir
If xFile = "" Then Exit Do
End If
'----------------------------------------------
uFile = ThisWorkbook.Path & "\" & xFile
Set uHead = Range("A65536").End(xlUp)
If uHead <> "" Then Set uHead = uHead(3, 1)
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & uFile, Destination:=uHead)
.AdjustColumnWidth = False
.TextFileColumnDataTypes = Array(1)
.Refresh BackgroundQuery:=False
.Delete
End With
uHead.Interior.ColorIndex = 6
'每筆第一格加〔黃色〕底
NEXT_LINE:
Loop
'-------------------------------------------------------
Application.ScreenUpdating = True
MsgBox "∼∼匯入完成∼∼ "
End Sub