Enable Microsoft Scripting Runtime permanantly

Tejas Kore

Board Regular
Joined
Nov 2, 2017
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Hi Friends,

I am using below FSO object because of my requirements. Because of this every time I run the code , I have to go to Menu Bar , select Tools --> References --> Microsoft Scripting Runtime and check it.

But it stays checked till the VB Editor is open .Once the editor is closed , I have to repeat the whole process again before running the program.

I wanted to know is there any way by which we can permanantly check the above said option ?

Public FSO As New FileSystemObject
Function listfiles(ByVal sPath As String)


Dim vaArray As Variant
Dim i As Integer
Dim oFile As Object
Dim oFSO As Object
Dim oFolder As Object
Dim oFiles As Object


Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files


ReDim vaArray(1 To oFiles.Count)
i = 1
For Each oFile In oFiles
vaArray(i) = oFile.Name
i = i + 1
Next


listfiles = vaArray

End Function
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi mole999,

First of all THANKS A LOT for sharing link.

Next thing which I wanted to tell is it worked when I tried with my code.
For adding Microsoft scripting runtime I used only one line in this function and removed other lines. But actually there are few more things written in there which I didn't understand , so thought better not to use them.
Now the code is running properly , should I worry about this ?

Sub AddRuntimeLibrary()

Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\scrrun.dll"

End Sub
 
Upvote 0
Actual Subroutine written there was this.

Sub AddRuntimeLibrary()
On Error Resume Next

'change this to your reference file C:\ ???

Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\scrrun.dll"

Const imgFileName = "PrintIcon"

'change the following to the GUID number that is shown on your sheet

Const GUIDRef = "{0002E157-0000-0000-C000-000000000046}" 'MS VBA EXTENSIBILITY 5.3 GUID

Set PrntIcon = Application.CommandBars.FindControl(ID:=4)

On Error Resume Next 'Ignore Error If Reference Already Established

'change the following 5, 3 to the GUID number that is shown on your sheet

ThisWorkbook.VBProject.References.AddFromGuid GUIDRef, 5, 3

On Error Resume Next

'change this to your reference file C:\ ???

Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\scrrun.dll"
End Sub
 
Upvote 0
just use the run time you need, i've had to do this when putting on a new machine and the reference wan't always available
 
Upvote 0
Code:
 Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\System32\scrrun.dll"

I have tried the code and I am getting a compile error: Invalid outside procedure
 
Upvote 0
you should really start a new thread, but i will ask what version of excel do you have, and does that file exist at that location
 
Upvote 0

Forum statistics

Threads
1,214,659
Messages
6,120,786
Members
448,992
Latest member
prabhuk279

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top