Advertisement
YasserKhalil2019

T3797_Copy Module To Multiple Closed Workbooks

Aug 25th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. https://excel-egy.com/forum/t3797
  2. ---------------------------------
  3.  
  4. Sub Copy_Module_To_Multiple_Closed_Workbooks()
  5. Dim wbkSource As Workbook
  6. Dim wbkTarget As Workbook
  7. Dim strFolder As String
  8. Dim strFile As String
  9. Dim strModule As String
  10.  
  11. Application.ScreenUpdating = False
  12. Application.EnableEvents = False
  13. Set wbkSource = ThisWorkbook
  14. strFolder = wbkSource.Path & "\حساب\عملاء\"
  15. strModule = strFolder & "modHassona.bas"
  16. wbkSource.VBProject.VBComponents("modHassona").Export Filename:=strModule
  17. strFile = Dir(PathName:=strFolder & "*.xls*")
  18.  
  19. Do While strFile <> ""
  20. Set wbkTarget = Workbooks.Open(Filename:=strFolder & strFile)
  21. With wbkTarget.VBProject.VBComponents
  22. On Error Resume Next
  23. .Remove VBComponent:=.Item("modHassona")
  24. On Error GoTo 0
  25. .Import Filename:=strModule
  26. End With
  27. wbkTarget.Close SaveChanges:=True
  28. strFile = Dir
  29. Loop
  30.  
  31. Kill strModule
  32. Application.EnableEvents = True
  33. Application.ScreenUpdating = True
  34.  
  35. MsgBox "Done...", 64
  36. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement