Can I get Excel not to save a file if certain information is not i

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to know if there is a way that I can set up a file that will not
allow someone to close it until certain cells are filled in.
 
In the Thisworkbook's codemodule, put this type of code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("Sheet1").Range("A1").Value = "" Then Cancel = True
If Worksheets("Sheet2").Range("B2").Value = "" Then Cancel = True
' and so on for each cell that you require to be filled in
End Sub
 
This can be done only with VBA code. In the ThisWorkbook code
module, use code similar to the following:


Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Range("A1") = "" Then ' change A1 to the desired cell
Cancel = True
End If
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



in message
news:[email protected]...
 
I am putting this info into Visual Basic Editor under Module - it is not
working I pasted yout code and inserted my information (i.e. sheet names and
cell numbers) but it is not working - do you know what I am doig wrong?
 
You need to double-click on the ThisWorkbook object of your workbook within the project explorer -
press Ctrl-R to get the project explorer to show - and then paste the code in the window that
appears.

HTH,
Bernie
MS Excel MVP
 

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