becci.gott
Board Regular
- Joined
- Oct 2, 2012
- Messages
- 79
I am automating the production of a load of output reports, and was getting a 400 Error when I tried to run. I have now narrowed it down and through the err.description have identified it as a 1004 error "The cell or chart you're trying to change is on a protected sheet. To make a change, unprotect the sheet. You might be requested to enter a password."
It specifically happens at the point of saving the copied sheets as the output filename. It seems to save without any problem, but then fails before it moves onto the next command (I did put a debug.print command in after the saveas, but it never got as far that).
I have even opened the saved file, and it exists, so I can't figure out how the hell to make this work!
I have used this exact same code in different macros (I have about 6 different workbooks that generate output reports), and it is only this one that is resulting in an error.
Edited to add that it works without issue if I F8 through the commands.
Any help would be greatly appreciated.
It specifically happens at the point of saving the copied sheets as the output filename. It seems to save without any problem, but then fails before it moves onto the next command (I did put a debug.print command in after the saveas, but it never got as far that).
I have even opened the saved file, and it exists, so I can't figure out how the hell to make this work!
Code:
'Set output path
strFilepath = ws.Range("FCSaveFilePath").Value & ws.Range("DateSubFolder").Value
strFilename = "Forecast Model - " & ws.Range("FileSuffix").Value
'Change strfilename incase of #N/A
strFilename = Replace(strFilename, "#N/A", "Client_Name Error")
filename = strFilepath & strFilename
'Copy report output sheets into new workbook
With Sheets(Array("Forecast Rolling 12 Months", "Report Rolling 12 Months", _
"Balance Sheet Assumptions", "3 Way Summary Forecast"))
.Select
.Copy
End With
Set nwb = ActiveWorkbook
'...Does some other bits in here that run without any issues...
'Save output report
With nwb
.SaveAs filename:=filename, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
.Close
End With
I have used this exact same code in different macros (I have about 6 different workbooks that generate output reports), and it is only this one that is resulting in an error.
Edited to add that it works without issue if I F8 through the commands.
Any help would be greatly appreciated.
Last edited: