Returns the number of drives : Drive « File Path « VBA / Excel / Access / Word






Returns the number of drives

 
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long

Function NumberofDrives() As Integer
    Dim Buffer As String * 255
    Dim BuffLen As Long
    Dim DriveCount As Integer
   
    BuffLen = GetLogicalDriveStrings(Len(Buffer), Buffer)
    DriveCount = 0
    For i = 1 To BuffLen
        If Asc(Mid(Buffer, i, 1)) = 0 Then _
          DriveCount = DriveCount + 1
    Next i
    NumberofDrives = DriveCount
End Function

Sub Main()
  Debug.Print NumberofDrives
End Sub

 








Related examples in the same category

1.Get Drive Information
2.The TypeOfDrive Function
3.The NumberOfBytesFree Function
4.Returns the number of free bytes for a drive
5.Returns the total storage capacity for a drive
6.Returns a string that describes the drive type
7.Returns True if a specified drive letter exists
8.Returns the drive letter using an index
9.Display Drive information