Put this in a new module, then call it using
Drive_Type("C" or whichever drive you are testing
Option Compare Database
Option Explicit
Public ndrive As String
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal ndrive As String) As Long
Public Function Drive_Type(driveletter As Variant) As Long
'Function returns type of drive based on passed drive letter
' 'Return Values
' '0=Can't Identify drive (error)
' '1=Drive Not Present
' '2=Removable (Floppy disk or Zip drive type)
' '3=Fixed (Hard Drive or Non-Removable Zip drive)
' '4=Remote (Network Drive)
' '5=CDROM
' '6=RAMDISK
ndrive = Left$(driveletter, 1) + ":\"
Drive_Type = GetDriveType(ndrive)
Select Case Drive_Type
Case 0
MsgBox "Can't Identify the Drive type"
Case 1
MsgBox "Drive type is " & "Not Present"
Case 2
MsgBox "Drive type is " & "Removable (Floppy disk or Zip drive type)"
Case 3
MsgBox "Drive type is " & "Fixed (Hard Drive or Non-Removable Zip drive)"
Case 4
MsgBox "Drive type is " & "Remote (Network Drive)"
Case 5
MsgBox "Drive type is " & "CD-ROM"
Case 6
MsgBox "Drive type is " & "RAM Disk"
End Select
End Function
additional info... if you want to test for drive letters A to Z then
Dim i As Integer, MyDriveLetter As String
For i = 65 To 90
MyDriveLetter = Chr(i)
If Drive_Type(MyDriveLetter) = 5 Then
MsgBox "Drive " & MyDriveLetter & " is a CD Drive"
'or do something else
End If
Next i
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.