Advertisement
YasserKhalil2019

T4588_Collate Sheets From XLSX Files Application StatusBar

Feb 1st, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. https://excel-egy.com/forum/t4588
  2. ---------------------------------
  3.  
  4. Sub Collate_Sheets_From_XLSX_Files_Application_StatusBar()
  5. 'اختيار المجلد الذي يحتوي على المصنفات المراد نسخ أوراق العمل منها
  6. Dim xFileDialog As FileDialog, xStrPath As String
  7. Set xFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
  8.  
  9. With xFileDialog
  10. .AllowMultiSelect = False
  11. .Title = "Select A Folder [Kutools For Excel - Excel-Egy]"
  12. If .Show = -1 Then xStrPath = xFileDialog.SelectedItems(1)
  13. If xStrPath = "" Then MsgBox "Operation Annulée", vbExclamation: Exit Sub
  14. End With
  15.  
  16. 'احتساب عدد المصنفات الموجودة في المجلد المحدد
  17. Dim fld As String, lst As Variant, num As Integer
  18. fld = Chr(34) & xStrPath & "\*.xlsx" & Chr(34)
  19. lst = Filter(Split(CreateObject("WScript.Shell").exec("cmd /c Dir " & fld & " /b /a-d").stdout.readall, vbCrLf), ".")
  20. num = UBound(lst) + 1
  21.  
  22. 'التعامل مع أول مصنف في المسار المحدد
  23. Dim xFile As String
  24. xFile = Dir(xStrPath & "\*.xlsx")
  25.  
  26. 'تحديد عدد المسافات في شريط الحالة
  27. Dim numberOfBars As Integer
  28. numberOfBars = 60
  29. Application.StatusBar = "[" & Space(numberOfBars) & "]"
  30.  
  31. 'بدء عملية النسخ وبدء الحلقة التكرارية
  32. Application.ScreenUpdating = False
  33. Do While xFile <> ""
  34. Dim wb As Workbook
  35. Set wb = Workbooks.Open(xStrPath & "\" & xFile)
  36.  
  37. 'استرجاع خاصية اهتزاز الشاشة لرؤية التقدم في شرط الحالة
  38. 'وتوضع هذه الأسطر داخل الحلقة التكرارية لبيان التقدم
  39. Dim cnt As Integer, currentStatus As Integer, pctDone As Integer
  40. Application.ScreenUpdating = True
  41. Application.Wait Now + TimeValue("00:00:03")
  42. cnt = cnt + 1
  43. currentStatus = Int((cnt / num) * numberOfBars)
  44. pctDone = Round(currentStatus / numberOfBars * 100, 0)
  45. Application.StatusBar = "[" & String(currentStatus, "|") & Space(numberOfBars - currentStatus) & "]" & " " & pctDone & "% Complete"
  46. Application.ScreenUpdating = False
  47.  
  48. 'نسخ أوراق العمل من المصنف المفتوح للمصنف الحالي ثم إغلاقه في النهاية
  49. Dim ws As Worksheet
  50. For Each ws In wb.Sheets
  51. ws.Copy After:=ThisWorkbook.Sheets(1)
  52. Next ws
  53. wb.Close False
  54.  
  55. xFile = Dir
  56. Loop
  57.  
  58. 'استرجاع شريط الحالة لما كان عليه قبل تنفيذ الكود
  59. Application.StatusBar = Empty
  60. Application.ScreenUpdating = True
  61.  
  62. MsgBox "Done...", 64
  63. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement