View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default Before_Close macro, How to...?

I am for sure missing some fundamental concept on how to make a Before_Close macro work.

I have tried several combinations of examples from google searches and none will check A1 to A200 for contents, I close the workbook, and it just closes with no action taken.

These are both in the ThisWorkbook module.

I can run the non-event code from the sheet "ABC" and it works just as I need.

I've tried calling the non-event from the Before_Close and it too does not respond.

Thanks,
Howard

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then

If WorksheetFunction.CountA(Sheets("ABC").Range("A1:A 200")) < 200 Then

Dim Reply As VbMsgBoxResult
Reply = MsgBox("Cells A1 to A200" _
& vbCr & "must have values" _
& vbCr & "before the workbook is closed", _
vbOKOnly + vbExclamation, "Two Hundred Empty!")

Else
End If
End If
'Cancel = True
End Sub


Sub MyCheckOnColumnA()

If WorksheetFunction.CountA(Sheets("ABC").Range("A1:A 200")) < 200 Then
Dim Reply As VbMsgBoxResult
Reply = MsgBox("Cells A1 to A200" _
& vbCr & "must have values" _
& vbCr & "before the workbook is closed", _
vbOKOnly + vbExclamation, "Two Hundred Empty!")

Else
End If

End Sub