Neil Humphries
New Member
- Joined
- Aug 1, 2018
- Messages
- 1
Windows 10, Excel 2016 The code is in a Module.
Three years ago, this code worked. Now it throws errors. Thetext of the error messages is different from that in the other threads I have seen with thesame error codes.
The code attempts to locate a button and delete it. There isonly one button per worksheet.
DeleteShapesByCaption "Create a new Schedule of Valuestab", wSht
Sub DeleteShapesByCaption( _
ByVal Caption AsString, _
Optional ByVal WSAs Worksheet = Nothing)
Dim Shp As Shape
If WS Is NothingThen Set WS = ActiveSheet
WS.UnprotectProtect_Password
For Each Shp InWS.Shapes
'What kind ofshape is it?
Select CaseShp.Type
CasemsoOLEControlObject
'May be acommandbutton
IfShp.OLEFormat.Object.Object.Caption = Caption Then
Shp.Delete 'This is where the error occurs
End If
Exit For
CasemsoFormControl
'May be abutton
IfShp.OLEFormat.Object.Caption = Caption Then Shp.Delete
End Select
Next
wSht.ProtectProtect_Password
End Sub
The error always occur at Shp.Delete
RTE 404 Object Required
RTE -2147024809 (80070057) The specified value is out ofrange
Context:
The workbook has a worksheet which is a template. Once thetemplate is filled in, it is copied for month 1. After the month 1 sheet iscompleted, the create a new sheet button is clicked to create a new sheet formonth 2 and the create a new sheet button is supposed to be removed from themonth 1 sheet. Each sheet only has one button.
I have used debug.print to confirm that the activesheet isthe previous month's sheet.
I have a version which moves from the back of the shapes collection to the front, but I still get the same -2147024809 (80070057) run time error with the same msg text.
This code worked properly in 2015. I have modified cellformulae to reflect changes in legislation, but I don't think those changes arerelevant because now even the 2015 workbook produces the errors.
The code executes as expected in creating the month 1 sheet.The only difference is that the create a new sheet button is not deleted from thetemplate page.
Three years ago, this code worked. Now it throws errors. Thetext of the error messages is different from that in the other threads I have seen with thesame error codes.
The code attempts to locate a button and delete it. There isonly one button per worksheet.
DeleteShapesByCaption "Create a new Schedule of Valuestab", wSht
Sub DeleteShapesByCaption( _
ByVal Caption AsString, _
Optional ByVal WSAs Worksheet = Nothing)
Dim Shp As Shape
If WS Is NothingThen Set WS = ActiveSheet
WS.UnprotectProtect_Password
For Each Shp InWS.Shapes
'What kind ofshape is it?
Select CaseShp.Type
CasemsoOLEControlObject
'May be acommandbutton
IfShp.OLEFormat.Object.Object.Caption = Caption Then
Shp.Delete 'This is where the error occurs
End If
Exit For
CasemsoFormControl
'May be abutton
IfShp.OLEFormat.Object.Caption = Caption Then Shp.Delete
End Select
Next
wSht.ProtectProtect_Password
End Sub
The error always occur at Shp.Delete
RTE 404 Object Required
RTE -2147024809 (80070057) The specified value is out ofrange
Context:
The workbook has a worksheet which is a template. Once thetemplate is filled in, it is copied for month 1. After the month 1 sheet iscompleted, the create a new sheet button is clicked to create a new sheet formonth 2 and the create a new sheet button is supposed to be removed from themonth 1 sheet. Each sheet only has one button.
I have used debug.print to confirm that the activesheet isthe previous month's sheet.
I have a version which moves from the back of the shapes collection to the front, but I still get the same -2147024809 (80070057) run time error with the same msg text.
This code worked properly in 2015. I have modified cellformulae to reflect changes in legislation, but I don't think those changes arerelevant because now even the 2015 workbook produces the errors.
The code executes as expected in creating the month 1 sheet.The only difference is that the create a new sheet button is not deleted from thetemplate page.