The array is fixed or temporarily locked.

broker

New Member
Joined
Nov 15, 2016
Messages
4
I have pasted here an Excel VBA code snippet that fails on the indicated line. I am using Microsoft 365. Any assistance would be greatly appreciated.

VBA Code:
Option Explicit
Option Base 1

Private Enum eCateg
   noObsolete = 0
   hasObsoleteSubfldrs = 1
   isOutOfDate = 2
End Enum
Private Type tyFldr
   pointr As Scripting.Folder
   categ As eCateg
   sw As Boolean
End Type

Private mFldr() As tyFldr

Private Sub FindObsoleteFolders(fldr As Scripting.Folder, isTopLevel As Boolean)
   Dim subfldr As Scripting.Folder, parnt As Scripting.Folder
   Dim protectedFldr As Boolean
   Dim m As Long
  
   If isTopLevel Then
      m = 1
      ReDim mFldr(1) As tyFldr
      With mFldr(1)
         Set .pointr = fldr
         .categ = hasObsoleteSubfldrs
         .sw = False
      End With
   End If
  
   For Each subfldr In fldr.SubFolders
      If isTopLevel Then
         protectedFldr = subfldr.Attributes = Hidden + System + Directory + Alias
      End If
     
      If protectedFldr Then
         protectedFldr = False
      Else
         m = m + 1
      '======== The following line runs fine when m = 2, but fails on m = 3.
      '======== Returns Err.Number = 10. Message reads, "The array is fixed or temporarily locked."
         ReDim Preserve mFldr(m) As tyFldr
         With mFldr(m)
            Set .pointr = subfldr
            .sw = isTopLevel Or .pointr.Name = "2023"
            If Not isObsolete(subfldr) Then
               .categ = noObsolete
               FindObsoleteFolders subfldr
            End If
         End With
      End If
   Next subfldr
  
End Sub

Private Function isObsolete(subfldr As Scripting.Folder) As Boolean
   'Loops thru a list of names of known obsolete folders, seeking match to subfldr.Name
   'Makes no reference to mFldr array.
End Function

Private Sub ProcessObsoleteFolder(fldr As Scripting.Folder)
   'Analyzes whether any file in the folder still has relevant data.
   'Makes no reference to mFldr array.
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top