【发布时间】:2016-04-27 18:28:15
【问题描述】:
它的作用:需要用户提供的字段。如果缺少特定字段,则阻止用户保存。在正确保存之前将这些字段变为红色。
我需要什么:好吧,我到底应该如何保存这个......
我想要什么:因为工作表是空白的。我无法保存。必填字段为红色。即使我可以保存,我也希望单元格在我推出之前没有填充。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xlSht As Worksheet
Dim cellsNotPopulated As Boolean
cellsNotPopulated = False
Set xlSht = ThisWorkbook.Worksheets("1st Call")
With xlSht
If .Range("F7") = "" Then
.Range("F7").Interior.Color = RGB(255, 0, 0)
cellsNotPopulated = True
Else
.Range("F7").Interior.ColorIndex = xlNone
End If
End With
If cellsNotPopulated = True Then
MsgBox "Please review the highlighted cells and ensure the fields are populated."
Cancel = True
End If
End Sub
【问题讨论】:
-
你能检查另一个值吗,所以 If .Range("F7") = "" and .Range("G7") ""