我已经看到很多有关此OLE操作错误的文章,但这里的区别在于,我正在运行的宏不会导入/导出任何数据,也不会在任何其他程序中触发操作(至少(不是故意的),这是我通常要学习的原因。这是生成错误的VBA:
Sub DeleteRows()
Dim varResponse As Variant
varResponse = MsgBox("This will permanently delete selected rows. Do you wish to continue?", vbYesNo, "WARNING")
If varResponse <> vbYes Then Exit Sub
Set Rs = Selection
For i = 1 To Selection.Rows.Count
If Range(Rs.Address).EntireRow.Cells(i, 12) <> "d" Then
MsgBox "Selection contains cells that can not be removed. Revise selection.", vbExclamation, "Invalid Selection"
Exit Sub
End If
Next
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Unprotect
Next
ActiveWorkbook.Worksheets("backup_estimate").Cells.Clear
ActiveWorkbook.Worksheets("backup_actual").Cells.Clear
ActiveWorkbook.Worksheets("backup_invoice").Cells.Clear
sourceOld = Selection(1).Row
sourceSize = Selection.Rows.Count
Worksheets("Estimate").Range(Rs.Address).EntireRow.Copy Destination:=Worksheets("backup_estimate").Range("A1")
Worksheets("Actual Cost").Range(Rs.Address).EntireRow.Copy Destination:=Worksheets("backup_actual").Range("A1")
Worksheets("Invoice Tracking").Range(Rs.Address).EntireRow.Copy Destination:=Worksheets("backup_invoice").Range("A1")
Sheets(Array("Estimate", "Actual Cost", "Invoice Tracking")).Select
Range(Rs.Address).EntireRow.Select
Selection.Delete Shift:=x1Up
ActiveSheet.Select
For Each Worksheet In ActiveWorkbook.Worksheets
Worksheet.Protect
Next
End Sub
宏的目的是删除此特定工作簿中6张纸中3张的相同数据选择和行,并将所有剩余数据上移。
触发宏时,它通常会冻结excel实例,并在大约10-20秒后将错误提示给我(并非每次都发生)。作为参考,“ backup_estimate”和其他备份表严格来说是临时数据存储,供我设置的另一个“撤消上一个动作”宏使用。
我确实有一个我定期使用的插件(蓝光束),但是在所有插件都被禁用并且选中了“忽略使用DDE的其他应用程序”选项的情况下,我遇到了此错误(一种修复方法在另一篇文章中建议)。