Search code examples
vba

how to check whether Scripting Runtime is available


Is there any way in VBA to determine whether the Scripting-Runtime aka scrrun.dll is disabled on a users system (here's a link on how to do that)?

I know, this is a very rare case, but it could be the case for exactly one client. There is another thread here but it's a little different.

Would you just go something like this?

Dim fso As Object

On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
On Error Goto 0

If fso Is Nothing then _
  MsgBox "Scripting runtime is not available on this system."


Solution

  • Yes, I would use this approach, it's as short as it can be:

    Public Function ScriptingRuntimeAvailable() As Boolean
        On Error Resume Next
    
        With CreateObject("Scripting.FileSystemObject"): End With
    
        ScriptingRuntimeAvailable = Err.Number = 0
    End Function