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