Hi tnsvolley,
See the attached sample copy of your file. You need the following code in the 'ThisWorkbook' code module of your file.
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim bHavePrerequisites As Boolean
bHavePrerequisites = VerifyPrerequisites()
If bHavePrerequisites = False Then
MsgBox "The Form can not be closed until the prerequisites on" & vbCrLf & _
"the 'Authorization' Tab have been filled in." & vbCrLf & vbCrLf & _
"Prerequisites are: b7:b12,h4,j7,m7,j8,m8,h9,h10"
Cancel = True
Exit Sub
End If
End Sub
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim bHavePrerequisites As Boolean
bHavePrerequisites = VerifyPrerequisites()
If bHavePrerequisites = False Then
MsgBox "The Form can not be printed until the prerequisites on" & vbCrLf & _
"the 'Authorization' Tab have been filled in." & vbCrLf & vbCrLf & _
"Prerequisites are: b7:b12,h4,j7,m7,j8,m8,h9,h10"
Cancel = True
Exit Sub
End If
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim bHavePrerequisites As Boolean
bHavePrerequisites = VerifyPrerequisites()
If bHavePrerequisites = False Then
MsgBox "The Form can not be saved until the prerequisites on" & vbCrLf & _
"the 'Authorization' Tab have been filled in." & vbCrLf & vbCrLf & _
"Prerequisites are: b7:b12,h4,j7,m7,j8,m8,h9,h10"
Cancel = True
Exit Sub
End If
End Sub
Private Function VerifyPrerequisites() As Boolean
'This returns True if all of the following cells are NOT BLANK:
'b7:b12,h4,j7,m7,j8,m8,h9,h10
Dim myRange As Range
Dim r As Range
Dim sRange As String
Dim sValue As String
sRange = "b7:b12,h4,j7,m7,j8,m8,h9,h10"
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Authorization")
Set myRange = ws.Range(sRange)
Debug.Print myRange.Address
'Initialize the return value to Verify
VerifyPrerequisites = True
'Process each cell in the range
'Get the Value (remove leading/trailing spaces)
'NOT VERIFY (and exit) if any cell is BLANK (length = 0)
For Each r In myRange
sValue = Trim(r)
If Len(sValue) = 0 Then
VerifyPrerequisites = False
Exit For
End If
Next r
Set ws = Nothing
End Function
It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
This option requires all variables to be declared and will give a compiler error for undeclared variables.
If you need help with Macros and/or VBA the following may help:
To enable Macros and to Run Macros see the following:
http://office.microsoft.com/en-us/ex...010031071.aspx
http://office.microsoft.com/en-us/ex...010014113.aspx
If help is still needed do a google search for 'youtube excel enable macro' and/or 'youtube excel run macro'.
To access Visual Basic (VBA) see:
http://www.ablebits.com/office-addin...a-macro-excel/
a. Click on any cell in the Excel Spreadsheet (may not be needed).
b. ALT-F11 to get to VBA.
c. CTRL-R to get project explorer (if it isn't already showing).
d. Double Click on a 'Module Name' in 'Project Explorer' to see code for that module.
Lewis
Bookmarks