我在我的代码中使用了FileSystem对象,它依赖于用户打开了他的微软脚本运行库。有没有代码可以让我在用户的Excel应用程序上打开这个库?
发布于 2015-09-15 16:25:19
您可以这样使用:
检查是否在VBAproject的references中未激活Scripting,然后添加它,否则不执行任何操作
Sub Test()
Dim Ref As Object, CheckRefEnabled%
CheckRefEnabled = 0
With ThisWorkbook
For Each Ref In .VBProject.References
If Ref.Name = "Scripting" Then
CheckRefEnabled = 1
Exit For
End If
Next Ref
If CheckRefEnabled = 0 Then
.VBProject.References.AddFromGUID "{420B2830-E718-11CF-893D-00A0C9054228}", 1, 0
End If
End With
End Sub发布于 2017-09-27 17:45:42
@Vasily的答案是有效的,但用户仍然需要在excel或任何其他微软办公程序中启用Trust Access to the VBA Project object model选项。
File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model
https://stackoverflow.com/questions/32578937
复制相似问题