如何在 VBA 中使用 FileSystemObject?
有什么我需要参考的吗?我如何使用它:
Dim fso As New FileSystemObject
Dim fld As Folder
Dim ts As TextStream
我收到错误,因为它无法识别这些对象。
Is there something that I need to reference? How do I use this:
Dim fso As New FileSystemObject
Dim fld As Folder
Dim ts As TextStream
I am getting an error because it does not recognize these objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 Excel 中,您需要设置对 VBScript 运行时库的引用。
相关文件通常位于
\Windows\System32\scrrun.dll
Visual Basic 编辑器 (ALT+F11)
Microsoft Scripting Runtime
”旁边的复选框scrrun.dll
的完整名称和路径> 文件将显示在列表框下方如果已启用对 VBA 对象模型的访问,也可以直接在代码中完成此操作。
可以通过勾选文件 > 中的
信任对 VBA 项目对象模型的访问
复选框来启用访问。选项>信任中心>信任中心设置>宏设置添加引用:
删除引用:
Within Excel you need to set a reference to the VBScript run-time library.
The relevant file is usually located at
\Windows\System32\scrrun.dll
Visual Basic Editor (ALT+F11)
Microsoft Scripting Runtime
'scrrun.dll
file will be displayed below the listboxThis can also be done directly in the code if access to the VBA object model has been enabled.
Access can be enabled by ticking the check-box
Trust access to the VBA project object model
found at File > Options > Trust Center > Trust Center Settings > Macro SettingsTo add a reference:
To remove a reference:
在 excel 2013 中,对象创建字符串是:
而不是上面答案中的代码:
In excel 2013 the object creation string is:
instead of the code in the answer above:
这些人提供了如何使用文件系统对象的优秀示例 http://www.w3schools.com/asp /asp_ref_filesystem.asp
These guys have excellent examples of how to use the filesystem object http://www.w3schools.com/asp/asp_ref_filesystem.asp
添加引用后,我必须使用
After adding the reference, I had to use
如上所述导入脚本运行时后,您必须进行一些细微的修改才能使其在 Excel 2010(我的版本)中工作。在下面的代码中,我还添加了用于用户选择文件的代码。
After importing the scripting runtime as described above you have to make some slighty modification to get it working in Excel 2010 (my version). Into the following code I've also add the code used to the user to pick a file.