先引用 Microsoft Scripting Runtime library,方法如下:
【工程】-->选择【引用】-->选择【Microsoft Scripting Runtime】(Scrrun.dll)
Private Sub Command1_Click()
On Error GoTo acd
Command1.Enabled = False
Dim FSO As FileSystemObject
Dim aDrive As Drive
Set FSO = New FileSystemObject
For Each aDrive In FSO.Drives
If aDrive.DriveType = CDRom And aDrive.IsReady = False Then
MsgBox "光驱中没有光盘!"
Exit For
ElseIf aDrive.DriveType = CDRom Then
MsgBox "光驱中有一张" & aDrive.VolumeName & "光盘"
Exit For
End If
Next
Set FSO = Nothing
Command1.Enabled = True
Exit Sub
acd:
MsgBox Err.Description
End Sub