Run Sub from Button

G

Guest

I found this code to open and close the coffe holder. I pasted it into a
Module

Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String,
ByVal _
lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _
hwndCallback As Long)

Public Sub OpenDefaultDiscTray()
mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
End Sub

Public Sub CloseDefaultDiscTray()
mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
End Sub

Then I added a button the spreadsheet and added this code which doesn't
work. i get "Compile Error. Sub or Function not defined." The code to open
the CD tray works, but not when i try to call it from a button click event.
This seems like it should be really simple, but I don't know what I'm doing
wrong.

Private Sub CommandButton1_Click()

Call OpenDefaultDiscTray

End Sub
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
B

Bernie Deitrick

Billy,

Works for me, though open is a bit slow for some reason...... Where is your code? The Private Sub
CommandButton1_Click() should be in the codemodule of the sheet that the button is on.

HTH,
Bernie
MS Excel MVP
 
G

Guest

I had it in a module in the Personal.xls I inserted a module and added a
code to the workbook that the button was on and it worked.
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 

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