Open/Close CD Tray using VBA

Vishesh's picture
Paste the following code in a module and try the two modules for open or close CD Tray.
Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
    ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
    ByVal hwndCallback As Long)
 
Sub CDTrayOpen()
    mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
End Sub
 
Sub CDTrayClose()
    mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
End Sub