0

I have used FileSystem Object in my code and it relies on the user having turned on his Microsoft Scripting Runtime Library. Is there a code by which I can turn on this library on the user's Excel application?

2 Answers2

1

you can use this way:
Check if Scripting is not activated in references of the VBAproject then add it otherwise do nothing

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
Vasily
  • 5,707
  • 3
  • 19
  • 34
0

@Vasily's answer works, but a user will still have to enable the option Trust Access to the VBA Project object model in excel or any other microsoft office program.

File -> Options -> Trust Center -> Trust Center Setttings -> Macro Settings -> Trust Access to the VBA Project object model

Thomascs
  • 75
  • 6