how to determin if a drive is ready

J

jay

How do you verify if a drive is ready using vba?
That is Cdrom, zip and usb drives.

I tried the vba below however it errors on a drive letter
that is not there such as a removed usb drive. It works with
the Zip and Cdrom but when a usb drive is removed it errors.



Dim fs, d

Set fs = CreateObject("Scripting.FilesSystemObject")
Set d = fs.GetDrive("h:")

If d.IsReady Then
Do this and that
End If
 
S

SteveM

I would just trap the error in your code and report it to the user.

To find the error codes to trap, use MsgBox Err.Number & Err.Description
then use structured error handling in your routine.

MySub()
On Error GoTo ErrHandler

'Your code here

Exit_Sub:
'Clean up code here
Exit Sub

ErrHandler:
Select Case Err.Number
Case 3043
MsgBox "The following error occured: "
Resume Exit_Sub
Case 3044
MsgBox "The following error occured: "
Resume Exit_Sub
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Sub
End Select

End Sub

Steve
 
J

jay

SteveM said:
I would just trap the error in your code and report it to the user.

To find the error codes to trap, use MsgBox Err.Number & Err.Description
then use structured error handling in your routine.

MySub()
On Error GoTo ErrHandler

'Your code here

Exit_Sub:
'Clean up code here
Exit Sub

ErrHandler:
Select Case Err.Number
Case 3043
MsgBox "The following error occured: "
Resume Exit_Sub
Case 3044
MsgBox "The following error occured: "
Resume Exit_Sub
Case Else
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Sub
End Select

End Sub



Looks like it is working now. Thanks
 

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

Top