【问题标题】:"Automation Error: Object Invoked has disconnected from its clients"“自动化错误:调用的对象已与其客户端断开连接”
【发布时间】:2020-08-06 12:54:39
【问题描述】:

我明白了尼克的建议,以下是我得到的错误编号和描述:

'-2147417848 (80010108)' 自动化错误调用的对象有 与客户断开连接

我调试时突出显示的代码行是:

.Rows(Lst).Insert Shift:=xlDown

我以为我在这个或另一个论坛上的某个地方看到了取消注册然后重新注册特定文件,但是当我遇到那个时我在家,并且不想在我的笔记本电脑上尝试它,因为一切已经 100% 工作了。

再次感谢任何帮助。我周日离开两周,我真的需要在离开之前完成这项工作。大多数为我工作的人都不是 excel 大师,需要所有按钮/功能正常工作,因为他们无法排除故障和/或解决问题。

我仍然在常规模块中使用以下代码,而下面的下一组代码在其中一个工作表模块中。

 Sub add_InvRow()
 Application.Calculation = xlCalculationManual
 Application.EnableEvents = False

 switch = "off"

 With ThisWorkbook
  Dim wb As Excel.Workbook, Lst As Long
  Set wb = Application.ThisWorkbook
Dim ws As Worksheet, sw As Worksheet, os As Worksheet
   Set ws = ActiveSheet: Set sw = Application.Sheets(Sheet1.Name): Set os = Application.Sheets(Sheet4.Name)

  With ws
  Lst = ActiveCell.Row
  End With
 
   If ws.CodeName = "Sheet3" Then
 
  With os
   .Rows(213).Copy
  End With

  With ws
 

   .Rows(Lst).Insert Shift:=xlDown
   Application.CutCopyMode = False
     
    venTabForm.Show
  End With
End If

If ws.CodeName = "Sheet23" Then
 
  With sw
   .Rows(135).Copy
  End With

  With ws
  
   .Rows(Lst).Insert Shift:=xlDown
   Application.CutCopyMode = False
     
    cItemForm.Show
  End With
End If
 
 If ws.CodeName = "Sheet25" Then
 
 With sw
   .Rows(105).Copy
  End With

  With ws
   
   .Rows(Lst).Insert Shift:=xlDown
   Application.CutCopyMode = False
     
   coInvForm.Show
  End With
 End If
 
 If ws.CodeName = "Sheet28" Then
      
  With sw
   .Rows(100).Copy
  End With
  
  With ws
   
   .Rows(Lst).Insert Shift:=xlDown
   Application.CutCopyMode = False
     
   kInvForm.Show
  End With
End If

If ws.CodeName = "Sheet27" Then
  
  With sw
   .Rows(130).Copy
  End With
  
  With ws
     .Rows(Lst).Insert Shift:=xlDown
     Application.CutCopyMode = False
     
     ItemForm.Show
  End With
End If
 
If ws.CodeName = "Sheet22" Then
  
  With sw
   .Rows(120).Copy
  End With

  With ws
   
   .Rows(Lst).Insert Shift:=xlDown
   Application.CutCopyMode = False
     
    caInvForm.Show
  End With
End If
 
 Set ws = Nothing: Set sw = Nothing: Set os = Nothing: Set wb = Nothing
End With

 switch = "on"
 Application.EnableEvents = True
 Application.Calculation = xlCalculationAutomatic
End Sub
  
  

此代码位于具有命令按钮的工作表之一上,该按钮调用上述代码。

 Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If switch = "off" Then Exit Sub
 If Target.Address = "$H$1" Then
  Call findItem
 Exit Sub
 End If


If Application.Intersect(Target, Me.Range("P:P")) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
If Target.Cells.Value = 0 Or Target.Cells.Value = "" Then Exit Sub
Dim wb As Workbook, ws As Worksheet, iNUM As String, kitSHT As Worksheet, ksRNG As Range, kITEM As Range, kbCELL As Range
Dim iNAME As String, catSHT As Worksheet, csRNG As Range, cbCELL As Range, cITEM As Range
Dim logCELL As Range



Set wb = ThisWorkbook: Set ws = wb.Sheets(Sheet27.Name): Set kitSHT = wb.Sheets(Sheet28.Name): Set catSHT = wb.Sheets(Sheet22.Name)
Set ksRNG = kitSHT.Range("C5:C1100"): Set kbCELL = ksRNG.Cells(5, 3)
Set csRNG = catSHT.Range("C6:C400"): Set cbCELL = csRNG.Cells(6, 3)


 If (Not (Application.Intersect(Target, Me.Range("A:P")) Is Nothing)) And (Target.Cells.Count = 1) And (Target.Column = 16) Then
  If Target.Value = 0 Then Exit Sub
   iNUM = Target.Offset(, -12).Value
   iNAME = Target.Offset(, -10).Value

   If kitSHT.Cells.Find(What:=iNUM, After:=kbCELL, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) Is Nothing And _
  catSHT.Cells.Find(What:=iNUM, After:=cbCELL, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) Is Nothing Then



    MsgBox iNUM & "-" & iNAME & "" & " is not currently listed on" & " " & kitSHT.Name & " " & "or" & " " & catSHT.Name & vbNewLine & vbNewLine & _
              "Please add" & " " & iNUM & "-" & iNAME & "" & " to" & " " & kitSHT.Name & " " & _
               "or" & " " & catSHT.Name & " " & "and corresponding count sheets", vbInformation
               
  Set wb = Nothing: Set ws = Nothing: Set kbCELL = Nothing
  Set ksRNG = Nothing: Set kitSHT = Nothing: Set cbCELL = Nothing: Set catSHT = Nothing: Set csRNG = Nothing
  Exit Sub
 Else
If Target.Value = 0 Then Exit Sub
  premNUM = iNUM


 pFORM.Show
 End If
 End If

  Set wb = Nothing: Set ws = Nothing: Set kbCELL = Nothing
  Set ksRNG = Nothing: Set kitSHT = Nothing: Set cbCELL = Nothing: Set catSHT = Nothing: Set csRNG = Nothing


  Set ksRNG = Nothing: Set kitSHT = Nothing: Set cbCELL = Nothing: Set catSHT = Nothing: Set csRNG = Nothing
End Sub




 

【问题讨论】:

  • 第一次尝试:最好使用Application.EnableEvents = False 来防止工作表更改...请尝试并判断错误是否仍然弹出...也尝试避免select(如果在非活动工作表中使用它会搞砸)。像.Rows(Lst).SelectSelection.EntireRow.Insert Shift:=xlDown 将是.Rows(Lst).Insert Shift:=xlDown :)
  • 在 Worksheet_Change 事件中,您同时拥有 If Target.Address = "$H$1"If Target.Address <> "H1"(即不一致的地址格式 - 两者都应该是 $H$1)。在此处使用文本比较不是一个好习惯 - 请改用 Application.Intersect,如下所示:If Not (Application.Intersect(Target, Me.Range("H1")) Is Nothing) Then
  • @barrowc - 我同意您的建议,但您提出的测试与 OP 使用的测试不同...
  • 不需要在过程结束时将对象变量设置为 Nothing。
  • @Tim Williams - 公平点 - If (Not (Application.Intersect(Target, Me.Range("H1")) Is Nothing)) And (Target.Count = 1) Then 将是相同的测试

标签: excel vba


【解决方案1】:

好的...现在已经 1 个多月了,我终于解决了这个问题!幸运的是,它与我的代码完全无关。相反,它是一个 MS Office Vs。 Windows 8 的问题。为了解决这个问题,我运行了兼容性疑难解答程序,一切又恢复了完美:

  1. 打开 MS Excel(任何文件或新文件)
  2. 拉起任务管理器
  3. 在后台进程中单击 MS Office 或 Excel 图标,右键单击,然后选择属性
  4. 在兼容性下,点击“运行兼容性疑难解答”
  5. 运行完成后,再次测试文件,如果正常,请单击将设置应用到该程序。如果它不起作用,请单击下一步并从选项中进行选择。 (我选择它在以前版本的 Windows(Windows 7)中工作,然后再次单击下一步。
  6. 再次测试文件,它成功了。

我不敢相信这就是我一直要做的一切!我实际上花了 149 美元,以为 Microsoft 支持可以远程修复它,但这绝对是浪费!我被调到了 12 多个不同的人/部门,但仍然一无所获。今天早上我终于偶然发现了解决方案....

无论如何,感谢所有发帖并试图帮助我的人。由于你们所有人,我总是以比我登录时更好的 VBA 技能退出此站点...所以再次感谢!

【讨论】:

    【解决方案2】:

    这个解决方案对我有用:

    在使用 Shift:=xlDown 添加行之前删除工作表上的底部行

    'ADD THE ROWS YOU WANT
    
    Sheets("XXXXXX").Range("A100000:A100100").EntireRow.Delete
    
    With Selection
    .Copy
    .Insert Shift:=xlDown
    End With
    

    【讨论】:

      【解决方案3】:

      确保您的工作表在插入时没有被锁定的单元格保护。这可能是代码失败的原因之一。这段代码在一个文件夹上为我工作,但是当我将 excel 宏文件复制到另一个文件夹时,我开始收到此错误。由于它仅用于格式化,我完全避免使用下面的代码,而是按照通常的方式进行格式化,而不是从上面的行中复制。 请注意,在第一个代码中,整行都被选中,如果您有受保护的单元格,则可能会导致失败。
      '行(r + 3 & ":" & r + 3).选择 'Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,有些宏对所有人都有效,但对 1 个人无效。

        我通过要求此人不要使用已同步到 OneDrive 的文件夹来解决此问题,因此在使用 OneDrive 时要小心。

        我遇到过其他情况,OneDrive 将从 BOX 或其他文件共享服务下载的文件标记为只读,并导致宏出错。您需要做的就是打开文件,保存并再次打开它,但很多人将其归咎于我的宏。我花了一段时间才找到原因,并找到一种方法来保存使用宏重新打开文件,然后才真正打开...

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-06-22
          • 2017-07-13
          • 1970-01-01
          • 2020-08-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多