有什么我需要参考的吗?我该如何使用这个:
Dim fso As New FileSystemObject
Dim fld As Folder
Dim ts As TextStream
我收到错误,因为它无法识别这些对象。
在 Excel 中,您需要设置对 VBScript 运行时库的引用。
相关文件通常位于\Windows\System32\scrrun.dll
- To reference this file, load the
Visual Basic Editor (ALT+F11)
- 从下拉菜单中选择工具 > 参考
- 将显示可用参考的列表框
- 勾选“旁边的复选框”
Microsoft Scripting Runtime
'
- 全名和路径
scrrun.dll
文件将显示在列表框下方
- Click on the OK button.
如果已启用对 VBA 对象模型的访问,也可以直接在代码中完成此操作。
可以通过勾选复选框来启用访问Trust access to the VBA project object model
发现于文件 > 选项 > 信任中心 > 信任中心设置 > 宏设置
要添加参考:
Sub Add_Reference()
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\scrrun.dll"
'Add a reference
End Sub
要删除引用:
Sub Remove_Reference()
Dim oReference As Object
Set oReference = Application.VBE.ActiveVBProject.References.Item("Scripting")
Application.VBE.ActiveVBProject.References.Remove oReference
'Remove a reference
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)