When I try to run this code, I get an error like this
Compile error
Can't find a project or library.
Public FSO As New FileSystemObject
Sub DiskSpace()
Dim drv As Drive
Dim Space As Double
Set drv = FSO.GetDrive("C:") ' Creating the the Drive object
Space = drv.FreeSpace
Space = Space / 1073741824 'converting bytes to GB
Space = WorksheetFunction.Round(Space, 2) ' Rounding
MsgBox "C: has free space = " & Space & " GB"
End Sub
scripting.tells the compiler where to look for the definitions ofFileSystemObjectandDrive. This avoids the need for a reference.