با سلام
در فایل پیوست فایلها در مسیر انتخاب شده ، لیست میگردد.
بعد از اجرای ماکرو ،ابتدا از پنچره باز شده مسیر فولدر مورد نظر را انتخاب کنید
کد PHP:
Sub Example1()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
Dim fDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
'Optional: FileDialog properties'
fDialog.Title = "Select Data folder"
fDialog.InitialFileName = "D:\"
If fDialog.Show = -1 Then
xx = fDialog.SelectedItems(1)
End If
'Create an instance of the FileSystemObject'
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object'
Set objFolder = objFSO.GetFolder(xx)
i = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
'loops through each file in the directory and prints their names and path'
For Each objFile In objFolder.Files
'print file name
Cells(i + 1, 1) = objFile.Name
'print file path'
Cells(i + 1, 2) = Left(objFile.Path, Len(objFile.Path) - Len(objFile.Name))
i = i + 1
Next objFile
End Sub
علاقه مندی ها (Bookmarks)