VBA Prank

msk7777

Active Member
Joined
Mar 30, 2004
Messages
280
I was wanting to play a trick on a few people in my department. I want to put a code in that when they enter any information in any cells it will post some type of message (lets just say for now I want it to say "xls. file corrupt, please close document and contact your Network Administrator"). Can anyone help me do this? Not to familar with VBA. Thanks!

msk7777
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

msk7777

Active Member
Joined
Mar 30, 2004
Messages
280
Those are all great tricks, but for someone like me I don't know how to do these, none of them really explain how to go about doing it.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Those are all great tricks, but for someone like me I don't know how to do these, none of them really explain how to go about doing it.
Hi,
depends what you mean by "explain"
for instance this code needs no explanation, supposed you know where to put the code...
Code:
Private Sub Workbook_Open() 
Application.DisplayAlerts = False 
Application.Quit 
End Sub
if you have questions about how to use, my suggestion would be to post it in the "Excel Questions" forum

your original question ...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "xls. file corrupt, please close document and contact your Network Administrator", 48, "ERROR"
End Sub
see http://www.cpearson.com/excel/events.htm

to make it more "real" you could let the code wait till 30 changes are made
then there is a chance of 1/10 (Rnd < 0.1) to get the popup
(change like you want)
in a "standard" module
Code:
Global cnt As Integer
in the sheetmodule
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
cnt = cnt + 1
If cnt > 30 And Rnd < 0.1 Then MsgBox "xls. file corrupt, please close document and contact your Network Administrator", 48, "ERROR"
End Sub
alternatively in the workbookmodule
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
cnt = cnt + 1
If cnt > 30 And Rnd < 0.1 Then MsgBox "xls. file corrupt, please close document and contact your Network Administrator", 48, "ERROR"
End Sub
remind: if you have more technical questions post in the "Excel Questions" forum, not in this chat-forum :)

kind regards,
Erik
 

msk7777

Active Member
Joined
Mar 30, 2004
Messages
280

ADVERTISEMENT

To be honest I don't know how this got moved into this forum, I posted it originally in Excel Questions. When I say "explained" I mean I don't really know how or where to put those codes, they look like fun and I want to play those pranks but I don't know how.

msk7777
 

Greg Truby

MrExcel MVP
Joined
Jun 19, 2002
Messages
10,014
:eek: It's been a while since I've read that thread in its entirety, but as I recall there were a couple of ideas in there that bordered on dangerous (or I might be remembering an older "funny pranks" thread in the old lounge). If you don't know what you're doing, proceed with caution. VBA pranks can be funny in the hands of a benevolent but orny feller who knows what he's doin'. VBA pranks might getcha fired if you accidentally blow something up. :eek:
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832

ADVERTISEMENT

When I say "explained" I mean I don't really know how or where to put those codes, they look like fun and I want to play those pranks but I don't know how.
even not after reading my reply ? did you check out the link (with extensive explanations)
 

msk7777

Active Member
Joined
Mar 30, 2004
Messages
280
I put the code into a module, saved and closed out of the workbook opened it back up and made some changes to the workbook and nothing happened? Did I maybe miss something?
 

Oorang

Well-known Member
Joined
Mar 4, 2005
Messages
2,071
No offense, but I agree with Greg. They are funny to talk about or show a friend, but most of those things you wouldn't want to actually do. And if you DO do them you would want to make sure there was no real damage. As a rule, if you aren't sure how code works or what it does you shouldn't use it in production. And when the code is pretty much guarenteed to cause trouble it is even less advisable. Remember that for every person causing trouble with a feature there are 5 that will scream to MS to make that feature less accessable.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
I put the code into a module, saved and closed out of the workbook opened it back up and made some changes to the workbook and nothing happened? Did I maybe miss something?
reading this it is like you've put everything in one single module, instead of following my explanation :confused: (which is straightforward to my sense)

of course agree with Greg: certainly when you do not know what you're doing
 

Forum statistics

Threads
1,136,263
Messages
5,674,710
Members
419,521
Latest member
Jasonnie

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
Top