ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Adding a Reference in VBA (https://www.excelbanter.com/excel-discussion-misc-queries/36876-adding-reference-vba.html)

Jim May

Adding a Reference in VBA
 
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



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



Jim May wrote:

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


--

Dave Peterson

Jim May

Thanks Dave; I made the change as you suggested.

"Dave Peterson" wrote in message
...
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



Jim May wrote:

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


--

Dave Peterson




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.

Jim May wrote:

Thanks Dave; I made the change as you suggested.

"Dave Peterson" wrote in message
...
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



Jim May wrote:

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


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com