vba 如何在 Excel 2010 for MAC 中安装/使用“Scripting.FileSystemObject”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4670420/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:30:18  来源:igfitidea点击:

How can I install/use "Scripting.FileSystemObject" in Excel 2010 for MAC?

macosexcelexcel-vbaexcel-vba-macvba

提问by Edward Tanguay

I am using Excel for Mac 2011which has VBA version 14.0.

我正在使用Excel for Mac 2011,它具有 VBA 版本 14.0。

I am trying to use this code which accesses the file system, which I know works on Windows:

我正在尝试使用此代码访问文件系统,我知道它在 Windows 上有效:

Function qfil_GetDirectory(strDirectoryName As String)

    Dim objFSO As Variant
    Dim objDirectory As Variant

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objDirectory = objFSO.GetFolder(strDirectoryName)
    Set qfil_GetDirectory = objDirectory

End Function

However, when I run it in Excel for Mac 2011, it gives me this error:

但是,当我在 Excel for Mac 2011 中运行它时,它给了我这个错误

Run-time error 429 Object creation with ActiveX component not possible

运行时错误 429 无法使用 ActiveX 组件创建对象

To fix this on Windows, I know I have to just reference a specific DLLunder tools.

要在 Windows 上解决这个问题,我知道我必须在工具下引用特定的DLL

However on the Mac, when I go under tools | referencesit onlygives me these:

但是在 Mac 上,当我使用工具时 | 引用只是给了我这些:

alt text

替代文字

And none of them allow me to use Scripting.FileSystemObject.

他们都不允许我使用Scripting.FileSystemObject.

What do I have to do in Excel 2011 for Mac so that I can use Scripting.FileSystemObject to read files from the hard drive from an Excel sheet via VBA?

我必须在 Excel 2011 for Mac 中做什么才能使用 Scripting.FileSystemObject 通过 VBA 从 Excel 工作表读取硬盘驱动器中的文件?

回答by trickwallett

To my knowledge, this approach won't be valid on Mac, as the external library doesnt exist.

据我所知,这种方法在 Mac 上无效,因为外部库不存在。

Don't know Office 11 VBA, but the Dir() function works accross platforms for '03.

不知道 Office 11 VBA,但 Dir() 函数适用于 '03 的跨平台。

回答by Ken White

Mac doesn't support ActiveX (it's a Windows technology), so you can't create the Scripting.FileSystemObject; it doesn't exist. (Even if it did, it's based on FAT32 or NTFS file systems, so it wouldn't work on OS X anyway.)

Mac 不支持 ActiveX(它是 Windows 技术),因此您无法创建 Scripting.FileSystemObject;它不存在。(即使是这样,它也是基于 FAT32 或 NTFS 文件系统的,因此无论如何它都无法在 OS X 上运行。)

回答by Chris Rae

If you're just trying to enumerate all the files in a folder, Codematichave a pretty good VBA module which should work fine on the Mac. It's not free, though.

如果您只是想枚举文件夹中的所有文件,Codematic有一个非常好的 VBA 模块,它应该可以在 Mac 上正常工作。不过,它不是免费的。