Making fields mandatory of a specific sheet on workbook save

前端 未结 3 1524
忘了有多久
忘了有多久 2021-01-03 12:39

I am using macros in excel to make fields mandatory in excel workbook. However, the problem is that the workbook contains multiple worksheets and the macro applies to all th

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 13:38

    More directly

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim ws As Worksheet
    Set ws = Sheets("Your sheet name here")
    If Len(ws.[b5]) = 0 Then
        MsgBox "Please fill cell B5 on sheet " & ws.Name, vbCritical, "File not saved"
        Cancel = True
        Application.Goto ws.[b5]
    End If
    End Sub
    

提交回复
热议问题