message box

S

swec74

I have been given a code to make a msg box pop up on opening the work book,
but is there any way to have that msg box pop up on a certain sheet insted of
it poping up when the work book opens?

thanks for any help given.
regards
Stuart
 
D

Don Guillett

right click sheet tab>view code>copy this>SAVE

Private Sub Worksheet_Activate()
MsgBox "I popped up"
End Sub
 
G

Gord Dibben

Right-click on the sheet tab and "View Code"

Paste these lines in that module.

Private Sub Worksheet_Activate()
''your pop-up message code goes here
End Sub

Delete the code from the module it presently resides in.

Gord Dibben Excel MVP
 
S

swec74

thank u it helpped alot :) but from that code is there any way to have it so
the message pops up for the first time i open the work book instead of every
time i click on the tab? thanks agian for ur help.
 
G

Gord Dibben

There are probably more elegant methods, but........

Copy/paste this to the worksheet.

Private Sub Worksheet_Activate()
If Range("A1").Value = "phnorton" Then Exit Sub
MsgBox "hoohah"
Range("A1").Value = "phnorton"
End Sub


Now copy/paste this to the ThisWorkbook Module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Range("A1").ClearContents
End Sub


Adjust range, sheetname and value to suit.


Gord
 

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