我想知道如何在打开它之前测试它。 例如,如果USB在E:或F上: 像这样:
if (?DriveExist?)
Workbooks.Open Filename:="E:"
else
Workbooks.Open Filename:="F:"
感谢您的帮助
答案 0 :(得分:6)
这样就可以了:
Function driveexists(DriveName As String)
Dim objDrv As Object
driveexists = False
For Each objDrv In CreateObject("Scripting.FileSystemObject").Drives
If DriveName = objDrv.DriveLetter Then driveexists = True
Next
Set objDrv = Nothing
End Function
所以你将它用作
IF driveexists("F") then...