warning or message before saving spreadsheet

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

Guest

I would like to have a message or warning to show up before saving a
spreadsheet template I've made if certain cells have been left empty. Is that
possible?
 
Yes it is.

Right click on a sheet's tab and choose View Code. In Project Explorer (if
it isn't displayed select it from the View menu) double click ThisWorkbook
under your template's name.

Use code something like (change A1 & B1 to reflect the cells that are of
concern to you)
===========================================

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Range("A1") = "" Or Range("B1") = "" Then
MsgBox "Must complete cells A1 & B1 before closing" _
, vbCritical, "Error"
Cancel = True
End If

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
If Range("A1") = "" Or Range("B1") = "" Then
MsgBox "Must complete cells A1 & B1 before closing" _
, vbCritical, "Error"
Cancel = True
End If

End Sub

===========================================
 
Try something like:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Range(A1) = "" Then
MsgBox "Err"
End If
End Sub

===== * ===== * ===== * =====
Daniel CHEN

Spreadsheet/VBA Specialist
(e-mail address removed)
www.Geocities.com/UDQServices
Your "Impossible" Task Could Be Someone Else's "Piece of Cake"
===== * ===== * ===== * =====
 

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