![](/img/trans.png)
[英]Run-time error '-2147024809 (80070057)' with erratic behavior
[英]New run time errors in older code 1004, 424, -2147024809 (80070057)
Windows 10,Excel 2016代碼位於模塊中。
三年前,此代碼奏效。 現在它會引發錯誤。 錯誤消息的文本與具有相同錯誤代碼的其他線程的文本不同。
該代碼嘗試找到一個按鈕並將其刪除。 每個工作表只有一個按鈕。
DeleteShapesByCaption "Create a new Schedule of Values tab", wSht
Sub DeleteShapesByCaption( _
ByVal Caption As String, _
Optional ByVal WS As Worksheet = Nothing)
Dim Shp As Shape
If WS Is Nothing Then Set WS = ActiveSheet
WS.Unprotect Protect_Password
For Each Shp In WS.Shapes
'What kind of shape is it?
Select Case Shp.Type
Case msoOLEControlObject
'May be a commandbutton
If Shp.OLEFormat.Object.Object.Caption = Caption Then
Shp.Delete 'This is where the error occurs
End If
Exit For
Case msoFormControl
'May be a button
If Shp.OLEFormat.Object.Caption = Caption Then Shp.Delete
End Select
Next
wSht.Protect Protect_Password
End Sub
該錯誤總是在Shp.Delete處發生
RTE 404對象必需
RTE -2147024809(80070057)指定的值超出范圍
語境:
該工作簿有一個工作表,它是一個模板。 填寫完模板后,將其復制到第1個月。完成第1個月的工作表后,單擊“創建新工作表”按鈕以為第2個月創建新工作表,並且應該刪除“創建新工作表”按鈕從第一個月開始。 每張紙只有一個按鈕。
我已經使用debug.print來確認活動表是上個月的表。
該代碼在2015年正常工作。我修改了單元格公式以反映立法方面的更改,但我認為這些更改無關緊要,因為即使現在2015年的工作簿也會產生錯誤。
該代碼將按照創建第1個月工作表中的預期執行。 唯一的區別是創建新圖紙按鈕不會從模板頁面中刪除。
遍歷集合以刪除某些成員時,向后工作比較安全:
DeleteShapesByCaption "Create a new Schedule of Values tab", wSht
Sub DeleteShapesByCaption( _
ByVal Caption As String, _
Optional ByVal WS As Worksheet = Nothing)
Dim Shp As Shape, i as Long
If WS Is Nothing Then Set WS = ActiveSheet
WS.Unprotect Protect_Password
For i = WS.Shapes.Count To 1 Step -1
Set Shp = WS.Shapes(i)
'What kind of shape is it?
Select Case Shp.Type
Case msoOLEControlObject
'May be a commandbutton
If Shp.OLEFormat.Object.Object.Caption = Caption Then
Shp.Delete 'This is where the error occurs
End If
Exit For
Case msoFormControl
'May be a button
If Shp.OLEFormat.Object.Caption = Caption Then Shp.Delete
End Select
Next i
wSht.Protect Protect_Password
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.