ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Validation data on exit Excel or save (https://www.excelbanter.com/excel-programming/352535-validation-data-exit-excel-save.html)

Atram Informatika

Validation data on exit Excel or save
 
How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit aplication, or
save document.

Thank's



Steve[_82_]

Validation data on exit Excel or save
 

The following workbook events should work


Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

"Atram Informatika" wrote in message
...
How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit aplication,
or
save document.

Thank's





Tom Ogilvy

Validation data on exit Excel or save
 
Use the Workbook level BeforeSave event.

If the workbook isn't saved, there is no need to validate the data


See Chip Pearson's page on events
http://www.cpearson.com/excel/events.htm


--
Regards,
Tom Ogilvy


"Atram Informatika" wrote in message
...
How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit aplication,

or
save document.

Thank's





Atram Informatika

Validation data on exit Excel or save
 
Thank's on your answer, for example how would code look like if the cell A1
can not be empty, how can i validate this befor exit or save. Thank's sorry
on my english.
"Steve" wrote in message
...

The following workbook events should work


Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

"Atram Informatika" wrote in message
...
How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit

aplication,
or
save document.

Thank's







Steve[_82_]

Validation data on exit Excel or save
 
Something along these lines


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim DataNotValid As Boolean

If IsEmpty(Range("A1")) Then DataNotValid = True

If DataNotValid Then
Cancel = True
End If
End Sub

"Atram Informatika" wrote in message
...
Thank's on your answer, for example how would code look like if the cell
A1
can not be empty, how can i validate this befor exit or save. Thank's
sorry
on my english.
"Steve" wrote in message
...

The following workbook events should work


Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'Validation check code here
'----
'----
'if data not valid then
'Cancel = True
'End If
End Sub

"Atram Informatika" wrote in message
...
How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit

aplication,
or
save document.

Thank's









Jim Thomlinson[_5_]

Validation data on exit Excel or save
 
in the ThisWorkbook module, there are event handlers for Before Save and
Before close. Both of these have arguments which if you set them to false
will cancel the save or the close. Be very careful with this kind of code
however because users get very frustrated when they can not save their work
or exit the program. If it is 5 o'clock and time to go home but they are only
half way done then what are they supposed to do. You are better off to use a
message box to let them know that the spreadsheet is not complete and then
prompt them if they wish to continue saving or exiting.
--
HTH...

Jim Thomlinson


"Atram Informatika" wrote:

How can I validate data when i exit excel aplication or when i save
workbook?
If data not valid then i must display message and do not exit aplication, or
save document.

Thank's





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com