Eject CD with Visual Basic?

A

Anthony Artist

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

Thank you.
 
A

Andy Pope

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
 
G

Glen Millar

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
 
A

Andy Pope

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
 
G

Glen Millar

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
 
A

Anthony

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

______________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top