Why do files remain in project window even after files closed?

前端 未结 1 1689
傲寒
傲寒 2021-01-29 10:38

Scenario

I have a userform, and when a button is pressed, it opens an Excel file as read-only, gets some values, and closes that file. Following are the

相关标签:
1条回答
  • 2021-01-29 11:01

    After many checks, it is found out that issue is not due to any codes. It is purely because of I am opening and closing a shared workbook. This type of issues are common when use shared workbooks. So it is best to avoid usage of shared workbooks.

    During these process some items I did to clear memory issue are

    1. Clear out variables and objects immediately after their usage.

      Eg: Set wb = nothing

    2. Open workbooks as read only whenever possible.

      Eg: Set wb = Workbooks.Open(blanketPo, ReadOnly:=True)

    3. Try to use ByRef instead of ByVal whenever possible while passing data. But please take care of the implication also when use these two
    4. After copied large set of data and finished the usage with such data, clear away that from memory by using Application.CutCopyMode = False
    5. Use the following code to empty clip board such as object and stuffs which were copied and keeping in clipboard while running macro. I got this code from another forum

      Dim DataObj As New MSForms.DataObject 'empty the clipboard DataObj.SetText "" DataObj.PutInClipboard

    Anyway the moment I choose not to use shared workbook, most of the memory and hang up issues disappeared. So its mostly all about the buggy shared workbook.

    0 讨论(0)
提交回复
热议问题