Xin chào Tôi đang cố liệt kê tất cả các tệp trong thư mục con nơi sổ làm việc Excel đang ở. Vì một số lý do, mã không thể thực thi vượt quá hàm Dir. Bất cứ ai có thể xin vui lòng tư vấn cho? Cảm ơn bạn!Chức năng Dir() không hoạt động trong Mac Excel 2011 VBA
Sub ListFiles()
ActiveSheet.Name = "temp"
Dim MyDir As String
'Declare the variables
Dim strPath As String
Dim strFile As String
Dim r As Long
MyDir = ActiveWorkbook.Path 'current path where workbook is
strPath = MyDir & ":Current:" 'files within "Current" folder subdir, I am using Mac Excel 2011
'Insert the headers in Columns A, B, and C
Cells(1, "A").Value = "FileName"
Cells(1, "B").Value = "Size"
Cells(1, "C").Value = "Date/Time"
'Find the next available row
r = Cells(Rows.Count, "A").End(xlUp).Row + 1
'Get the first file from the folder
'Note: macro stops working here
strFile = Dir(strPath & "*.csv", vbNormal)
'Loop through each file in the folder
Do While Len(strFile) > 0
'List the name, size, and date/time of the current file
Cells(r, 1).Value = strFile
Cells(r, 2).Value = FileLen(strPath & strFile)
Cells(r, 3).Value = FileDateTime(strPath & strFile)
'Determine the next row
r = r + 1
'Get the next file from the folder
strFile = Dir
Loop
'Change the width of the columns to achieve the best fit
Columns.AutoFit
End Sub
gì "không thể thực hiện "có nghĩa là chính xác? Có thông báo lỗi không? Nội dung chính xác của 'strPath' khi thực thi dừng lại là gì? –