View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Adam Harding Adam Harding is offline
external usenet poster
 
Posts: 9
Default beforesave and beforeclose

Thanks Norman

All sorted wroks a treat.

Thnaks for your help.

"Norman Jones" wrote:

Hi Adam,

If the value of M2 can be 0 or nothing (no entry), then try:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Cancel = Me.Sheets("Detailed_Cost_Sheet").Range("M2").Value = 0

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Cancel = Me.Sheets("Detailed_Cost_Sheet").Range("M2").Value = 0
End Sub

If M2 must have an entry and equal 2, try instead:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim rng As Range

Set rng = Me.Sheets("Detailed_Cost_Sheet").Range("M2")
If Not IsEmpty(rng) Then
Cancel = rng.Value = 0
End If

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim rng As Range

Set rng = Me.Sheets("Detailed_Cost_Sheet").Range("M2")
If Not IsEmpty(rng) Then
Cancel = rng.Value = 0
End If

End Sub


---
Regards,
Norman



"Adam Harding" wrote in message
...
Am looking to disable saving and closing subject to field M2 = 0 i am
trying

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = (Me.Sheets(1).Cells(1, 1) = _
Me.Sheets(2).Cells(1, 1))
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Cancel = (Me.Sheets(1).Cells(1, 1) = _
Me.Sheets(2).Cells(1, 1))
End Sub

But not knnowing VB that well am running into errors. My worksheet is
called
Detailed_Cost_Sheet and is sheet 4. so what should my VB say?

Cheers