Object invoked has disconnected from its clients w

2019-09-11 23:47发布

I keep getting a

Object invoked has disconnected from its clients

from running this line

Workbooks("LastParamChanges").Sheets("LastChanges").Range("A9").EntireRow.Insert shift:=xlDown

When the error message pops up and I click debug to go to that line, I click F8 to continue to the next line, another error message pops up saying

Runtime Error 1004: Insert method of Range class has failed

I also have Application.DisplayAlerts and Application.EnableEvents set to False if that helps.

1条回答
2楼-- · 2019-09-11 23:50

I had the same problem. The solution that worked for me was to add this code before the .Insert statement:

Dim oldValue As Variant
With Workbooks("LastParamChanges").Sheets("LastChanges")
  .Range("B1").Activate
  oldValue = .Range("B1").Value
  .Range("B1").ClearContents
  .Range("B1").Value = oldValue
End With

It seems that you first need to edit the sheet before inserting any rows.

查看更多
登录 后发表回答