vba CreateObject("Scripting.FileSystemObject") 在 Excel for Mac 下不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23448686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CreateObject("Scripting.FileSystemObject") doesn't work under Excel for Mac
提问by SoftTimur
I have a piece of VBA code which is used to get subfolders given a path, it works well under Excel for Windows
:
我有一段 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
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
.
现在我想在Excel for Mac
(版本:2011 14.4.1)下运行此代码。它在行给出错误Set fso = CreateObject("Scripting.FileSystemObject")
。错误信息是Run-time error '429': ActiveX component can't create object
。
Could anyone help me debug it?
谁能帮我调试一下?
采纳答案by citizenkong
The FileSystemObject is part of the Windows scripting library, which doesn't exist on Mac OSX.
FileSystemObject 是 Windows 脚本库的一部分,它在 Mac OSX 上不存在。
Similar question asked previously: How can I install/use "Scripting.FileSystemObject" in Excel 2010 for MAC?
之前问过的类似问题: 如何在 Excel 2010 for MAC 中安装/使用“Scripting.FileSystemObject”?