# VBA Prank



## msk7777 (Sep 29, 2006)

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


----------



## Oaktree (Sep 29, 2006)

You'd probably enjoy this thread:

http://www.mrexcel.com/board2/viewtopic.php?t=28037


----------



## msk7777 (Sep 29, 2006)

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 (Sep 29, 2006)

> 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...

```
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 ...

```
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

```
Global cnt As Integer
```
in the sheetmodule

```
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

```
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 (Sep 29, 2006)

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 (Sep 29, 2006)

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.


----------



## erik.van.geit (Sep 29, 2006)

> 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 (Oct 2, 2006)

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 (Oct 2, 2006)

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 (Oct 2, 2006)

> 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   (which is straightforward to my sense)

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


----------



## msk7777 (Oct 2, 2006)

I thank everyone for their concern, but this is one of my creations and if it gets messed up I am the one that has to fix it.  Plus I am trying it out on a copy of one to see what happens.  

erik.van.geit:

I did read what you wrote me, and I only did the code for what I originally asked for, didn't want to try to much out at once.  I created a new module and copied your code into it, clicked save and then exited out and re-opened it.  There are other modules already in there and was wondering if they may be interfering?  If so then I will just leave this alone.


----------



## erik.van.geit (Oct 2, 2006)




----------



## gingerafro (Oct 3, 2006)

> 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?



Now THATS a prank.


----------



## msk7777 (Oct 3, 2006)

I got it to work, thanks everyone, I will keep reading into what you sent me, that is a lot to read and practice and learn.  Thanks!


----------

