Can you....

A

Aversin

Can you create a text box that pops up when you try to exit excel?
would like a box that reminds people to fill out parts of a form whe
they try to exit the workbook.

Any ideas would be great
 
K

kkknie

This code goes in the ThisWorkbook section of the VB Editor.

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Dim iResponse As Long

iResponse = MsgBox("Did you enter everything? Click No to return an
finish.", vbYesNo)
If iResponse = 7 Then Cancel = True

End Sub

If the user clicks No, the application will not close. You coul
modify this to check for certain cells having values in them and onl
pop up this message if they were blank. Something like:

If Sheets("Sheet1").Range("A4").Value = "" Or _
Sheets("Sheet1").Range("A6").Value = "" Or _
Sheets("Sheet1").Range("A8").Value = "" Then

'Bring up the message.

End If
 
A

Aversin

If Sheets("Sheet1").Range("A4").Value = "" Or _
Sheets("Sheet1").Range("A6").Value = "" Or _
Sheets("Sheet1").Range("A8").Value = "" Then


If I added this code could I just write

If Sheets("Sheet1").Range("A4").Value="True"Or _

or does it need to be a function like Value>0 Or_


Sorry for all the questions, I'm just new :
 
F

Frank Kabel

Hi
you can. But probably your cell contains a boolean value so you may
have to use
If Sheets("Sheet1").Range("A4").Value= True Or _
 
A

Aversin

What am I doing worong?

Private Sub Workbook_BeforeClose(Cancel As Boolean)



If Sheets("Sheet1").Range("A4").Value = "False" Or _
Sheets("Sheet1").Range("A6").Value = "False" Or _
Sheets("Sheet1").Range("A8").Value = "False" Then
Dim iResponce As Long
iResponce = MsgBox("Get back to work.", vbYesNo)
If iResponce = 7 Then Cancel = True
End If


End Su
 
F

Frank Kabel

Hi
try removing the apostrophes. e.g.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("Sheet1").Range("A4").Value = False Or _
Sheets("Sheet1").Range("A6").Value = False Or _
Sheets("Sheet1").Range("A8").Value = False Then
Dim iResponce As Long
iResponce = MsgBox("Get back to work.", vbYesNo)
If iResponce = 7 Then Cancel = True
End If


End Sub
 
Top