ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Message Box Warning (https://www.excelbanter.com/excel-programming/425571-message-box-warning.html)

Tio Pepe

Message Box Warning
 
I want to write a macro that will show a warning message box when the user
filling out a form, created in Excel 2003 as a template, trys to close or
save the form without modifying the contents of a particular cell that
contains text that states that "You must enter a reason in this area"

Jacob Skaria

Message Box Warning
 
Hi Tio

Open workbook template. Launch VBE and paste the below code within the
"ThisWorkbook" object. Post back for any help..Thanks

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

'Here Range("A1") is assumed as mandatory and Range("A2") the comment field
If Trim(Range("A2")) < "" And Trim(Range("A2")) = "You must enter a reason
in this area" Then
MsgBox "Please fill the comments", vbInformation, "Form name"
Cancel = True
End If
End Sub


If this post helps click Yes
---------------
Jacob Skaria


All times are GMT +1. The time now is 02:12 AM.

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