Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Hold closing the sheet...


Hi

I have to validate the data at the time of closing the sheet. If some errors are present in the data, I need to throw a message and I should not close the sheet.

I am using the following code to achieve it. Here the problem is I can throw an error message if the data is wrong but how to stop the work book from closing. I have to give a chanse to user to correct the data. How this can be achieved?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

{ Validate the data }

If Error Msgbox ( " Error .... Correct the Data " )

End Sub

--
Message posted via http://www.officekb.com
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Hold closing the sheet...

I would use the BeforeSave and BeforeClose events in
conjunction with each other. Here's an example:

'//Constructive criticism from VBA programmers appreciated

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As _
Boolean, Cancel As Boolean)
Dim checkRng As Range
Set checkRng = Sheets("Sheet1").Range("A1")
If IsError(checkRng) Then
Cancel = True
MsgBox "Error found in " & _
checkRng.Address(False, False) & "."
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved = False Then
MsgBox "Please save before closing."
Cancel = True
End If
End Sub


--
Both macros should be placed in the ThisWorbook module.

HTH
Jason
Atlanta, GA

-----Original Message-----

Hi

I have to validate the data at the time of closing the

sheet. If some errors are present in the data, I need to
throw a message and I should not close the sheet.

I am using the following code to achieve it. Here the

problem is I can throw an error message if the data is
wrong but how to stop the work book from closing. I have
to give a chanse to user to correct the data. How this
can be achieved?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

{ Validate the data }

If Error Msgbox ( " Error .... Correct the Data " )

End Sub

--
Message posted via http://www.officekb.com
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how i open another sheet in the same workbook without closing? kamrul Excel Discussion (Misc queries) 2 February 14th 09 08:31 AM
Warning upon closing sheet stevieboy1313 Excel Worksheet Functions 6 April 22nd 08 06:53 PM
How to find and Replace hyperlink in hold sheet? Wiparat Excel Discussion (Misc queries) 1 August 5th 07 11:40 AM
How can I hold every other row color on a sheet when I sort Proto Excel Discussion (Misc queries) 1 September 28th 06 12:52 PM
set time limit before closing sheet Maria Johansson Excel Programming 2 October 14th 03 08:00 AM


All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"