انتقل إلى المحتوى الرئيسي

كيفية سرد كافة المجلدات والمجلدات الفرعية في إكسيل؟

هل سبق لك أن عانيت من هذه المشكلة التي تسرد جميع المجلدات والمجلدات الفرعية من دليل محدد في ورقة عمل؟ في Excel ، لا توجد طريقة سريعة وسهلة للحصول على اسم جميع المجلدات الموجودة في دليل معين مرة واحدة. للتعامل مع المهمة ، قد تساعدك هذه المقالة.

سرد كافة المجلدات والمجلدات الفرعية برمز VBA


السهم الأزرق الحق فقاعة سرد كافة المجلدات والمجلدات الفرعية برمز VBA

إذا كنت ترغب في الحصول على جميع أسماء المجلدات من دليل محدد ، فقد يساعدك رمز VBA التالي ، فيرجى القيام بذلك على النحو التالي:

1. اضغط باستمرار على ALT + F11 مفاتيح ، ويفتح نافذة ميكروسوفت فيسوال باسيك للتطبيقات.

2. انقر إدراج > وحدة، والصق الكود التالي في ملف نافذة الوحدة.

رمز فبا: سرد كافة المجلدات وأسماء المجلدات الفرعية

Sub FolderNames()
'Update 20141027
Application.ScreenUpdating = False
Dim xPath As String
Dim xWs As Worksheet
Dim fso As Object, j As Long, folder1 As Object
With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Choose the folder"
    .Show
End With
On Error Resume Next
xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
xWs.Cells(1, 1).Value = xPath
xWs.Cells(2, 1).Resize(1, 5).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.getFolder(xPath)
getSubFolder folder1
xWs.Cells(2, 1).Resize(1, 5).Interior.Color = 65535
xWs.Cells(2, 1).Resize(1, 5).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Sub getSubFolder(ByRef prntfld As Object)
Dim SubFolder As Object
Dim subfld As Object
Dim xRow As Long
For Each SubFolder In prntfld.SubFolders
    xRow = Range("A1").End(xlDown).Row + 1
    Cells(xRow, 1).Resize(1, 5).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified)
Next SubFolder
For Each subfld In prntfld.SubFolders
    getSubFolder subfld
Next subfld
End Sub

3. ثم اضغط F5 مفتاح لتشغيل هذا الرمز ، و اختر المجلد ستظهر النافذة ، فأنت بحاجة إلى تحديد الدليل الذي تريده لإدراج أسماء المجلدات والمجلدات الفرعية ، انظر لقطة الشاشة:

قائمة أسماء المجلدات doc-1

4. انقر OK، وستحصل على مسار المجلد والمجلدات الفرعية والدليل والاسم وتاريخ الإنشاء وتاريخ آخر تعديل في مصنف جديد ، انظر لقطة الشاشة:

قائمة أسماء المجلدات doc-1


مقالة ذات صلة:

كيفية سرد الملفات في دليل لورقة العمل في إكسيل؟

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
Comments (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, I don't want or need it to show all that information nor the subfolders nor the filenames & I especially don't want it to create a new file altogether! What I need is simply just the top level folder names only in a non changing directory. Because unfortunately people at my work don't comprehend the need for uniformity in naming folders & also they move folders into an old job folder ruining any possible easy excel function links.
Example:
C:\temp\
>folder1
>folder2
>folder3
Etc. Etc. Etc...
Thats all I need.
The Way that apparently everyone on the internet wants; darn near crashes excel &/or my work PC trying to list every bit of over 15,000 instances of every single unwanted file & subfolder for this query.
There's only about 40 Give-Or-Take folders w/in the directory.
I already have a way of determining if files are w/in as example folder2 or not.
I am trying to automate this away from my current solution which was creating a folder w/ a text file for each, named the exact name of each folder. But if someone adds moves renames or deletes a folder this no longer fully works. AND I absolutely do not want to use command prompt.
I want & need either an excel function or vba option that I can use in conjunction w/ other excel functions i have &/or create w/in the same document (different sheets are fine).
This comment was minimized by the moderator on the site
Great work... It's very helpful for me, thanks very much
This comment was minimized by the moderator on the site
Thank you, this is exactly what we needed to record the folders for our clients.
This comment was minimized by the moderator on the site
Thank you very much for this usefull code. is that possible save result in same workbook not to new one ?
This comment was minimized by the moderator on the site
This worked and how... Thank you so much. Just one addition-- at Step 3, I had to click on Step Into and then only did the F5 key work for choosing the folder.
This comment was minimized by the moderator on the site
Thank you so much!, very useful.
This comment was minimized by the moderator on the site
Just what I needed, and perfectly clear instructions on how to make it work. Thanks a lot
This comment was minimized by the moderator on the site
Great Tool! After long research found this accurate toy :)
This comment was minimized by the moderator on the site
Hello. Can you please please help me on a code which I am struggling to find.

Below are the requirements for the code.



1. The VBA should go through all the folders and sub-folders
and check each and every type of file. The user should only give the path for
the top folder. The code should then check all the folders and sub folders
within the top folder.



2. After checking the files, the code should zip all files
which have not been accessed for more than 3 months. The accessed period is
something which I should be able to change in future if required. It should
allow me to change it to 1 month or 5 months if required.



3. After zipping the files, the code should delete the
original files which were zipped.



4. The zipped file should be saved in the same path as the
original file.
This comment was minimized by the moderator on the site
I modified it to add size:



Sub FolderNames()
'Update 20141027
Application.ScreenUpdating = False
Dim xPath As String
Dim xWs As Worksheet
Dim fso As Object, j As Long, folder1 As Object
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Choose the folder"
.Show
End With
On Error Resume Next
xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\"
Application.Workbooks.Add
Set xWs = Application.ActiveSheet
xWs.Cells(1, 1).Value = xPath
xWs.Cells(2, 1).Resize(1, 6).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified","Size")
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder1 = fso.getFolder(xPath)
getSubFolder folder1
xWs.Cells(2, 1).Resize(1, 6).Interior.Color = 65535
xWs.Cells(2, 1).Resize(1, 6).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
Sub getSubFolder(ByRef prntfld As Object)
Dim SubFolder As Object
Dim subfld As Object
Dim xRow As Long
For Each SubFolder In prntfld.SubFolders
xRow = Range("A1").End(xlDown).Row + 1
Cells(xRow, 1).Resize(1, 6).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified, SubFolder.Size)
Next SubFolder
For Each subfld In prntfld.SubFolders
getSubFolder subfld
Next subfld
End Sub
This comment was minimized by the moderator on the site
When you include the SubFolder.Size function the script no longer list all the subfolders, only the first level.
How can I include the size and get all subfolders listed?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations