Can you....

  • Thread starter Thread starter Aversin
  • Start date Start date
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
 
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
 
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 :
 
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 _
 
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
 
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
 

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

Back
Top