Option Explicit Sub GetDirNames() Const Path = "D:\Working\AZ Training\VBA Excel\Exercise\" Dim strFileName As String strFileName = Dir(Path & "*.xl*") Do While strFileName <> "" Range("A65536").End(xlUp)(2).Value = Path & strFileName strFileName = Dir Loop End Sub
Lưu ý: Đoạn code trên không hỗ trợ tốt với các file tiếng Việt có dấu (trả lại tên file “Số liệu tháng 1.xlsx” là “S? li?u tháng 1.xlsx”). Để sử dụng được tiếng Việt có dấu chúng ta có thể sử dụng đoạn code sử dụng “FileSystemObject (FSO) trong VBA Excel”