Sub GetFile()
Dim mPath, nFile, mFolder As String, nRow As Integer
mPath = InputBox("NHap ten duong dan, vi du nhu D:\Report")
'mPath = "D:\WorkSpace\DuAnTrienKhai"
If Right(mPath, 1) <> "\" Then mPath = mPath & "\"
nRow = 1
'=================================================
'Kiem Tra su ton tai cua Sheet("TEMP"):
Dim Zs As Object
On Error Resume Next
Set Zs = ActiveWorkbook.Sheets("TMP")
If Err = 0 Then
Sheets("TMP").Cells.Delete
Else
Sheets.Add
ActiveSheet.Name = "TMP"
End If
Worksheets("TMP").Range("A1").Value = mPath
'=================================================
'Ghi vao sheet tam truoc khi xuat ra file txt:
With Worksheets("TMP").Range("A1")
nFile = Dir(mPath & "*.*", vbSystem)
Do While nFile <> ""
nFile = Dir
.Offset(nRow, 0).Value = nFile
nRow = nRow + 1
Loop
End With
'=================================================
'Xuat ra File txt:
Dim MyPath As String, MyFileName As String
Dim NewBook As Workbook
MyPath = "D:\"
MyFileName = InputBox("Nhap ten file can luu:", "Export from excel to text")
Sheets("TMP").Activate
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=MyPath & MyFileName & ".txt", _
FileFormat:=xlUnicodeText, CreateBackup:=False
ActiveWorkbook.Close True
End Sub