Good Excel Practical Jokes, Pranks, Mean Tricks, etc.

Barry -

He probably figures if he removes it, you'll just go and do something else. See what happens if you remove it. <g>
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Eddie , to get you started :
Rich (BB code):
Option Explicit
'source : http://www.freevbcode.com/ShowCode.asp?ID=68

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

Sub OpenOrShutCDDrive(DoorOpen As Boolean)
Dim lRet As Long
If DoorOpen Then
    lRet = mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
    lRet = mciSendString("Set CDAudio door closed", 0&, 0&, 0)
End If

'lRet will = 0 upon success, so if you want to make this
'a function, return true if lret = 0, false otherwise
End Sub

Sub OpenCD()
OpenOrShutCDDrive (1)
End Sub

Sub CloseCD()
OpenOrShutCDDrive (0)
End Sub

Loving this! lol

How can this be set to repeat (Open, then close) every 15 seconds?

I really need to wind someone up in the office

Also - can it be set to run automatically on opening the document?
 
So how do you actually do this?

I copied and pasted the code into the workbook module of a new book to see how it worked, but what triggers the event ?

also, anyone got the 15 second repeater thingy going yet?

ta
 
Rich (BB code):
Option Explicit
'source : http://www.freevbcode.com/ShowCode.asp?ID=68

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


Sub OpenOrShutCDDrive(DoorOpen As Boolean)
Application.OnTime Now + TimeValue("0:30:00"), "OpenCD"
Dim lRet As Long
If DoorOpen Then
    lRet = mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
    MsgBox ("Please Play Better Music")
Else
    lRet = mciSendString("Set CDAudio door closed", 0&, 0&, 0)
End If

'lRet will = 0 upon success, so if you want to make this
'a function, return true if lret = 0, false otherwise
End Sub

Sub OpenCD()
OpenOrShutCDDrive (1)
End Sub

Sub CloseCD()
OpenOrShutCDDrive (0)
End Sub
 
I get :

Compile error:
Only comments may appear after end sub, end function, or end property

then it highlights :

Private Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal _
pstrReturnString As String, ByVal uReturnLength As Long, ByVal _
wndCallback As Long) As Long
 
Thanks man but it dont work if i put it in there

Yes it does:

Code:
Private Sub Workbook_Open()
    OpenCD
End Sub

Where did you put the Open event? It needs to go in the ThisWorkbook module; the rest of the code goes in a standard module.

Smitty
 

Forum statistics

Threads
1,215,334
Messages
6,124,325
Members
449,154
Latest member
pollardxlsm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top