I have a piece of VBA code which is used to get subfolders given a path, it works well under Excel for Windows
:
Function GetSubFolders(RootPath As String)
Dim fso As Object
Dim fld As Object
Dim sf As Object
Dim myArr
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(RootPath)
For Each sf In fld.SUBFOLDERS
Counter = Counter + 1
ReDim Preserve Arr(Counter)
Arr(Counter) = sf.Path
myArr = GetSubFolders(sf.Path)
Next
GetSubFolders = Arr
Set sf = Nothing
Set fld = Nothing
Set fso = Nothing
End Function
Now I would like to run this code under Excel for Mac
(version: 2011 14.4.1). It gives an error at the line Set fso = CreateObject("Scripting.FileSystemObject")
. The error message is Run-time error '429': ActiveX component can't create object
.
Could anyone help me debug it?