3

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?

Community
  • 1
  • 1
SoftTimur
  • 5,630
  • 38
  • 140
  • 292

1 Answers1

2

The FileSystemObject is part of the Windows scripting library, which doesn't exist on Mac OSX.

Similar question asked previously: How can I install/use "Scripting.FileSystemObject" in Excel 2010 for MAC?

Community
  • 1
  • 1
citizenkong
  • 679
  • 5
  • 14
  • Please see this [meta question about duplicates](http://meta.stackoverflow.com/questions/252047/answering-a-duplicate). Duplicates should be flagged as such. – RubberDuck May 05 '14 at 18:36