(VBA)为什么我的工作表变得非常大,当我使用锁性能locking一个大范围?

我有一个大约11MB的工作表(85k行,70列)。 然后我运行下面的macros解锁两个范围,安全我的工作表,然后工作表是87MB大。 为什么会发生? 我该如何改变呢?

PS:范围非常大

Sub unprotect() Dim lastRow, lastColumn, firstRow, firstColumn As Variant ActiveSheet.unprotect firstRow = 2 firstColumn = 32 lastRow = ActiveSheet.Cells(Rows.Count, 5).End(xlUp).row '85k lastColumn = 350 With ActiveSheet.Range(Cells(firstRow, 1), Cells(lastRow, 2)) .Locked = False 'unlock the cells, so they can be edited in a protected sheet End With With ActiveSheet.Range(Cells(firstRow, firstColumn), Cells(lastRow, lastColumn)) .Locked = False End With ActiveSheet.protect 'protect the sheet so only unlocked cells can be edited End Sub 

主要原因是通过设置单元格被locking为false,您已经从使用85K行70列(约6百万个单元格)到使用85K行(略低于350列)(略低于30,000,000个单元格) 5左右增加。

尝试像这样:

 Sub unprotect() Dim lastRow as long dim lastColumn as long dim firstRow as long dim firstColumn as long With ActiveSheet .unprotect firstRow = 2 firstColumn = 32 lastRow = .Cells(.Rows.Count, 5).End(xlUp).row '85k lastColumn = 350 .Range(.Cells(firstRow, 1), .Cells(lastRow, 2)).Locked = False .Range(.Cells(firstRow, firstColumn), .Cells(lastRow, lastColumn)).Locked = False .protect End With End Sub 

这里有一些关于范围对象 – https://msdn.microsoft.com/en-us/library/office/ff194567.aspx

如果不起作用,请使用以下代码删除其他样式(如果有的话):

 Sub RemoveTheStyles() Dim style As style Dim l_counter As Long Dim l_total_number As Long On Error Resume Next l_total_number = ActiveWorkbook.Styles.Count Application.ScreenUpdating = False For l_counter = l_total_number To 1 Step -1 Set style = ActiveWorkbook.Styles(l_counter) If (l_counter Mod 500 = 0) Then DoEvents Application.StatusBar = "Deleting " & l_total_number - l_counter + 1 & " of " & l_total_number & " " & style.Name End If If Not style.BuiltIn Then style.Delete Next l_counter Application.ScreenUpdating = True Application.StatusBar = False Debug.Print "READY!" On Error GoTo 0 End Sub 

这两个解决scheme之一应该给出一些结果。