Check Drive Space

  • Thread starter Thread starter Charles
  • Start date Start date
C

Charles

Hi is it possible to write code to check available space
on a drive from Excel?.
TIA
Charles
 
Here is a routine posted by Jim Rech a while back

Declare Function GetDiskFreeSpaceExA Lib "kernel32" _
(ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfBytes As Currency) As Boolean

Sub ShowDiskSpace()
Dim MyFreeSpace As Currency
Dim MyTotalSpace As Currency
Dim TotalFreeSpace As Currency
If GetDiskFreeSpaceExA("c:\", _
MyFreeSpace, _
MyTotalSpace, _
TotalFreeSpace) Then
MyFreeSpace = MyFreeSpace * 10000
MyTotalSpace = MyTotalSpace * 10000
TotalFreeSpace = TotalFreeSpace * 10000
MsgBox "Total space on drive: " & _
Format(MyTotalSpace, "#,###bytes") & Chr(13) & _
"Free space: " & Format(MyFreeSpace, "#,### bytes")
End If
End Sub
 
a bit simpler alternative to using api..

Function FreeKB(DriveSpec As String)
With CreateObject("Scripting.FileSystemObject")
If Not .DriveExists(DriveSpec) Then
FreeKB = CVErr(xlErrRef)
Else
FreeKB = .GetDrive(DriveSpec).FreeSpace \ 1024
End If
End With
End Function



keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
but depends upon Scripting being allowed, not true in many commercial
environments
 

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

Similar Threads


Back
Top