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

末鹿安然 提交于 2020-01-25 05:56:25

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/23448686/createobjectscripting-filesystemobject-doesnt-work-under-excel-for-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!