用下面的宏代碼可以打開(kāi)或關(guān)閉電腦中默認(rèn)的光驅(qū)。方法是:
1.按Alt+F11打開(kāi)VBA編輯器。
2.在代碼窗口中輸入下列代碼:
Private Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
ByVal hwndCallback As Long)
Sub OpenDefaultCDDVD()
‘打開(kāi)光驅(qū)
mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
End Sub
Sub CloseDefaultCDDVD()
‘關(guān)閉光驅(qū)
mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
End Sub