Hi,
I am fairly new to the whole Macro scene and need some help please. I am looking for a macro that will copy a sheet from 1 workbook and copy it into several closed workbooks, all saved in the same folder. I have been playing with the below but can't seem to get it to work. Any help greatly appreciated.
Sub CopySheet()
Const strFldrPath As String = "C:\Workbook Problems\" 'Where the workbooks are all saved
Dim CurrentFile As String, FileExt As String, wb As Workbook, wsActive As Worksheet, ThisExt As String
Set wsActive = ActiveWorkbook.ActiveSheet
If InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) > 0 Then
ThisExt = StrReverse(Left(StrReverse(ActiveWorkbook.Name), InStr(1, StrReverse(ActiveWorkbook.Name), ".", vbTextCompare)))
Else
ThisExt = ".xlsx"
End If
CurrentFile = Dir(strFldrPath)
While CurrentFile <> vbNullString
FileExt = StrReverse(Left(StrReverse(CurrentFile), InStr(1, StrReverse(CurrentFile), ".", vbTextCompare)))
If LCase(ThisExt) = ".xls" Then
If LCase(FileExt) = ".xls" Or LCase(FileExt) = ".xlsx" Or LCase(FileExt) = ".xlsm" Then
Set wb = Workbooks.Open(Filename:=strFldrPath & CurrentFile)
wsActive.Copy Before:=wb.Sheets(1)
wb.Close True
End If
Else
If LCase(FileExt) = ".xlsx" Or LCase(FileExt) = ".xlsm" Then
Set wb = Workbooks.Open(Filename:=strFldrPath & CurrentFile)
wsActive.Copy Before:=wb.Sheets(1)
wb.Close True
End If
End If
CurrentFile = Dir()
Wend
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub
Bookmarks