没有足够的内存资源可用于完成此操作

Not enough memory resources are available to complete this operation

场景

我有两个用户表单,当我单击第一个用户表单中的按钮时,第二个用户表单将显示并卸载第一个用户表单。

问题

当我点击第二个用户表单中的 listbox 时出现内存错误

我的userform2如下

错误如下

下面是userform2

中的全部代码
Private Sub UserForm_Initialize()

        Dim reportWbi As Workbook
        Dim internal As Worksheet

        Set reportWbi = Workbooks.Add(reportFile)
        Set internal = reportWbi.Worksheets("Internal")
        internal.Select

        LastAddress = internal.Range("C" & Rows.Count).End(xlUp).Address
        ListBox2.RowSource = "C6:" & LastAddress

        reportWbi.Close savechanges:=False
        Set reportWbi = Nothing
        Set internal = Nothing
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    reportCreator.Show
End Sub

其实里面并没有多少变量和东西。一一调试后,发现没有下面这几行,就没有内存错误

    reportWbi.Close savechanges:=False
    Set reportWbi = Nothing
    Set internal = Nothing

我给出行 reportWbi.Close savechanges:=False 的那一刻,它正在抛出内存错误。

请注意,我使用的是 Office 365 和 8Gb 内存。我认为这不会引起任何问题

有谁知道哪里出了问题吗?

编辑 1

我尝试将整个代码放入一个品牌 excel 文件中,该文件只有一个用户表单并且存在相同的内存错误。我删除 reportWbi.Close savechanges:=False 的那一刻,一切正常,没有任何错误

编辑 2

我删除了 ListBox2.RowSource = "C6:" & LastAddress 代码,这次即使有 reportWbi.Close savechanges:=False 也没有错误

很困惑为什么会这样。如果对此有任何了解,请有人帮助

经过一些试验,发现问题是由于 ListBox2.RowSource = "C6:" & LastAddress 这个 RowSource 属性。我不知道为什么它会导致内存问题。我删除了它并使用下面的一些其他循环方法填充 Listbox2

        Range("C6").Select
        Do While ActiveCell.Value <> ""
            With ListBox2
                .AddItem ActiveCell.Value
            End With
            ActiveCell.Offset(1, 0).Select
        Loop

现在没有内存问题,一切正常