Eject CD with Visual Basic?

  • Thread starter Thread starter Anthony Artist
  • Start date Start date
A

Anthony Artist

Is it possible to create a macro to eject a CD?
If yes, what is the code?

Thank you.
 
Hi Anthony,

This code works for me.

Option Explicit
'
' Need to include a reference to winmm.dll
' Use Tools > References > Browse
'
Public Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" _
(ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) As Long
Public Sub EjectCD()
mciSendString "Set CDAudio Door Open Wait", 0&, 0&, 0&
End Sub
Public Sub CloseCD()
mciSendString "Set CDAudio Door Closed Wait", 0&, 0&, 0&
End Sub


Anthony said:
Is it possible to create a macro to eject a CD?
If yes, what is the code?

Thank you.

--

Cheers
Andy

http://www.andypope.info
 
Andy,

Cool vba and nice web site! Although I haven't tested the vba, I know
someone will!

--
Regards,

Glen Millar
Microsoft PPT MVP
http://www.powerpointworkbench.com/
Please tell us your ppt version, and get back to us here
Remove spaces from signature
Posted to news://msnews.microsoft.com
 
Hi Glen,

Glad you liked the site.

As you can probably tell I'm more an Excel kinda guy, but I do keep an
eye on you powerpoint types ;)

Glen said:
Andy,

Cool vba and nice web site! Although I haven't tested the vba, I know
someone will!

--

Cheers
Andy

http://www.andypope.info
 
Andy,

I started in Excel, but found I could achieve more change in people through
presenting data rather than developing it <g>.

Anyway, 11 pm so night all!

--
Regards,

Glen Millar
Microsoft PPT MVP
http://www.powerpointworkbench.com/
Please tell us your ppt version, and get back to us here
Remove spaces from signature
Posted to news://msnews.microsoft.com
 
Thanks (for the code and the link to the site both)

I've *got* to find time to have a play with your listbox class. That looks SO
intriguing ...
 
Andy,

Thanks for taking the time to respond.

Just for interest I found an variant at
http://www.visualbasicforum.com/t137394.html

Best wishes,
Anthony
______________________________

Private Declare Function mciSendString Lib "winmm.dll"
Alias "mciSendStringA" (ByVal lpstrCommand As String, _
ByVal lpstrReturnString As String, ByVal uReturnLength As
Long, ByVal hwndCallback As Long) As Long

Function vbmciSendString(ByVal Command As String, ByVal
hWnd As Long) As String

Dim Buffer As String
Dim dwRet As Long
Buffer = Space$(100) ' Create a buffer
dwRet = mciSendString(Command, ByVal Buffer, Len(Buffer),
hWnd)
vbmciSendString = Buffer

End Function

Private Sub Eject_Click()
Dim sEjectCD As String
sEjectCD = vbmciSendString("set cdaudio door open", 0)
End
End Sub

______________________
 
Back
Top