I have used the code below to change the codename ie sheet1, sheet2 etc to match the order of the sheets in the workbook. Now when I try to run it I get a run-time error 1004. I'm not sure what changed or what could be causing the error. I think I got much of the code from this board or one like it in the past, but didn't note where. Any ideas what could cause the run-time error?
Code:
Sub Renumber_Sheets()
Dim ws As Worksheet
Dim x As Integer
x = 3000 'a number greater than the total number of sheets in workbook
For Each ws In Worksheets 'rename all sheets to avoid conflicts
ws.Parent.VBProject.VBComponents(ws.CodeName).Properties("_CodeName") = "Sheet" & x
x = x + 1
Next
x = 1 'start with first sheet in workbook
For Each ws In Worksheets 'rename all sheets to sheet order
ws.Parent.VBProject.VBComponents(ws.CodeName).Properties("_CodeName") = "Sheet" & x
x = x + 1
Next
End Sub