I'm creating a new Book then opening files in a directory and adding the corresponding sheets and values to the new Book. I've gone through so many forms showing the "Copy Destination:=" or just one range equal to the other, but I can't get my script work. Everything is working (this is just a snippet, so trust me 98% of it works) except this ONE line right before "Workbooks(FileName).Close" in the Else scenario. I normally find my answer and figure it out, but I turn in the towel here. Help please!
Dim SiteUsedCheck As Boolean
Dim NewBook As Workbook
Dim NewSheet As Worksheet
Dim SaveAsName As String
Dim WeekRange As Range
Set WeekRange = Range("I5:O17")
SaveAsName = "Invoice" & "_" & Home.Range("C23").Value & ".xlsm"
MsgBox SaveAsName
Set NewBook = Workbooks.Add
With NewBook
Do While FileName <> "" '<---recall FileName variable looks at excele books; it ignores folders
Workbooks.Open (Directory & FileName)
If Workbooks(FileName).Worksheets("TotalHours").Cells(SecretTest, WeekCol) = 0 Then
Workbooks(FileName).Close
Else
Dim TempSheetName As String
Set NewSheet = .Sheets.Add(After:=.Sheets(.Sheets.Count))
TempSheetName = Workbooks(FileName).Worksheets("TotalHours").Range("B2").Value
NewSheet.Name = TempSheetName
NewBook.Sheets(TempSheetName).Range("A1").Value = Workbooks(FileName).Sheets("TotalHours").Range("WeekRange") '<--This is the line that keeps getting an error. But if I put a "1" on the right side of the = it works. So what's wrong with this tiny piece?
Workbooks(FileName).Close
End If
FileName = Dir()
Loop
.SaveAs FileName:= _
InvoiceDirectory & SaveAsName _
, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Workbooks(SaveAsName).Close
End With