Good morning,
I am trying to copy a single sheet to 219 different workbooks. I tried this code yesterday on a coupel of empty test workbooks (completely new to VB) and it worked perfectly.....this morning I'm trying to run it for real but I'm getting a couple of error messages ..... at the moment 'Run-time error 9 : Subscript out of range'.
Any advice would be much appreciated!
Option Explicit
Public Sub CopySheetToAllWorkbooksInFolder()
Dim sourceSheet As Worksheet
Dim folder As String, filename As String
Dim destinationWorkbook As Workbook
'Worksheet in active workbook to be copied as a new sheet to the 219 workbooks
Set sourceSheet = ActiveWorkbook.Worksheets("16-17")
'Folder containing the 219 workbooks
folder = "
\\ash-dc01\FolderRedirection\DHendricksen\Desktop\MacroTest\"
filename = Dir(folder & "*.xls", vbNormal)
While Len(filename) <> 0
Debug.Print folder & filename
Set destinationWorkbook = Workbooks.Open(folder & filename)
sourceSheet.Copy before:=destinationWorkbook.Sheets(1)
destinationWorkbook.Close True
filename = Dir() ' Get next matching file
Wend
End Sub
TIA