4

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?

0

1 Answer 1

3

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?

Sign up to request clarification or add additional context in comments.

1 Comment

Please see this meta question about duplicates. Duplicates should be flagged as such.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.