Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CreateObject("Scripting.FileSystemObject") doesn't work under Excel for Mac [duplicate]

Tags:

excel

vba

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?

like image 992
SoftTimur Avatar asked Nov 14 '25 11:11

SoftTimur


1 Answers

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?

like image 89
citizenkong Avatar answered Nov 17 '25 07:11

citizenkong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!