Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://excel-egy.com/forum/t4570
- ---------------------------------
- Sub Copy_Worksheet_Module_To_Multiple_Closed_Workbooks()
- Dim src, dest, wb As Workbook, ws As Worksheet, strFolder As String, strFile As String
- Application.ScreenUpdating = False
- Application.EnableEvents = False
- 'Change Sheet1 With Source Worksheet Name
- Set src = ThisWorkbook.VBProject.VBComponents("Sheet1").CodeModule
- strFolder = ThisWorkbook.Path & "\Sample Folder\"
- strFile = Dir(PathName:=strFolder & "*.xls*")
- Do While strFile <> ""
- Set wb = Workbooks.Open(Filename:=strFolder & strFile)
- For Each ws In wb.Worksheets
- 'Change Sheet1 With Target Worksheet Name
- Set dest = wb.VBProject.VBComponents(ws.Name).CodeModule
- dest.DeleteLines 1, dest.CountOfLines
- dest.AddFromString src.Lines(1, src.CountOfLines)
- Next ws
- wb.Close SaveChanges:=True
- strFile = Dir
- Loop
- Application.EnableEvents = True
- Application.ScreenUpdating = True
- MsgBox "Done...", 64
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement