如何解决宏停止在CreateObject(“ System.Collections.Queue”)处的自动化错误?在旧计算机上工作而不是新的

时间:2019-06-18 20:53:40

标签: excel vba createobject

该宏应该计算和删除重复项,该重复项显示单词右侧的重复项,但在行Set words = CreateObject("System.Collections.Queue")处停止。我使用了一些使用此CreateObject("System.Collections.Queue")的宏。所有这些宏都可以在我的旧计算机上工作,而不能在我的新笔记本电脑上工作。相同的代码。可能是什么问题?我假设("System.Collections.Queue")存在问题,因为当前有错误的所有宏都有此问题。有人可以帮我,以便我可以修复所有宏吗?

    Sub CountAndDeleteDupes()

        Dim cell As Range
        Dim i As Integer
        Dim j As Integer
        Dim count As Integer
        Dim startRow As Integer
        Dim startCol As Integer
        startRow = Selection.Row
        startCol = Selection.Column

        Dim words As Object
        Set words = CreateObject("System.Collections.Queue")
        Dim counts As Object
        Set counts = CreateObject("System.Collections.Queue")

        For Each cell In Selection
            j = 1
            count = 1
            If Not cell.Value = "" Then
                For i = j To Selection.Rows.count
                    If UCase(cell.Value) = UCase(Cells(cell.Row + i,     cell.Column).Value) Then
                    'If UCase(cell.Value) = UCase(cell.Offset(i).Value) Then
                        count = count + 1
                        Cells(cell.Row + i, cell.Column).Value = ""
                        'cell.Offset(i).Value = ""
                    End If
                Next i
                counts.enqueue (count)
                words.enqueue (cell.Value)
            End If
            j = j + 1
            cell.Clear
        Next cell

        For i = 1 To words.count
            Cells(startRow + i - 1, startCol).Value = words.dequeue
            Cells(startRow + i - 1, startCol + 1).Value = counts.dequeue
        Next i

        End Sub
  

运行时错误'-2146232576(80131700)':自动化错误

0 个答案:

没有答案