Adding a Reference in VBA

J

Jim May

In order to run the below code what is the Official
exact name of the library I should have added/checked
in my Reference table?
TIA,

Sub Tester1()
Dim fso As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\Documents and Settings\Jim\My Documents")
MsgBox "You have " & fldr.Files.Count & " Files in the Excel Formulas
Folder"
End Sub
 
D

Dave Peterson

microsoft scripting runtime

But then you could change your code to:

Sub Tester2()
Dim FSO As Scripting.FileSystemObject
Dim FLDR As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set FLDR = FSO.GetFolder("C:\Documents and Settings\Jim\My Documents")
MsgBox "You have " & FLDR.Files.Count & " Files in the Excel Formulas Folder"
End Sub
 
J

Jim May

Thanks Dave; I made the change as you suggested.

Dave Peterson said:
microsoft scripting runtime

But then you could change your code to:

Sub Tester2()
Dim FSO As Scripting.FileSystemObject
Dim FLDR As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set FLDR = FSO.GetFolder("C:\Documents and Settings\Jim\My Documents")
MsgBox "You have " & FLDR.Files.Count & " Files in the Excel Formulas
Folder"
End Sub
 
D

Dave Peterson

In general, I'd use the code with the references while developing, but before I
distribute the code, I'll remove the reference, change the declarations, fix the
constants and release it that way.

The resulting code will work slightly slower, but you don't have to worry about
giving the workbook to a pc that has a different version of the reference I
used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top