Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004

    Unanswered: VB in Excel: Preventing Saving Until A Condition is Met


    Im very new to VB and am wondering whether it is possible to prevent users saving a worksheet in excel if a certain condition is not met. Basically if they do not enter text, say in column H, is it possible to prevent them from saving the worksheet. If not, is it possible to bring up a Message Box prompting them to fill in the field?

    Any help would be really appreciated,


  2. #2
    Join Date
    Jan 2004
    Aberdeen, Scotland

    Re: VB in Excel: Preventing Saving Until A Condition is Met

    In the ThisWorkbook Code you can set the Event Handler workbook beforesave such as

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
        If Range("H65536").End(xlUp).Row = 1 Then
            Cancel = True
        End If
    End Sub
    this checks if there is anything in any cell in column H bar row 1.
    the Cancel = True Cancels the Save Event.

    To Get into ThisWorkbook code get into VBA Window (Press Alt+F11)
    and Double click on thisworkbook under the Project Explorer.

    Hope this Helps


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts