CreateObject(" Scripting.FileSystemObject")在Excel for Mac下不起作用

时间:2014-05-03 19:07:47

标签: vba excel-vba excel

我有一段VBA代码用于获取给定路径的子文件夹,它在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

现在我想在Excel for Mac(版本:2011 14.4.1)下运行此代码。它在行Set fso = CreateObject("Scripting.FileSystemObject")处出错。错误消息为Run-time error '429': ActiveX component can't create object

有人可以帮我调试吗?

1 个答案:

答案 0 :(得分:1)

FileSystemObject是Windows脚本库的一部分,在Mac OSX上不存在。

之前提出的类似问题:How can I install/use "Scripting.FileSystemObject" in Excel 2010 for MAC?