excel - 阻止 Excel 用户使用 X、最小化和最大化按钮关闭电子表格
问题描述
如果单元格 H40 不包含文本值,我需要一些帮助来阻止 Excel 中的电子表格关闭。
这是一个范围的宏,而不是单个单元格:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Sheets("Daily Centre Inputs").Range("D6,F6,C8:C18,I6:I18,A22:K22,A29,A36,H36").Value = "" Then
MsgBox "Incomplete fields. Please check your data ensuring any required cells are complete otherwise you will not be able to close or save the workbook"
Cancel = True
End If
End Sub
解决方案
这将在 H40 更改且为空时触发。您需要将其添加到您希望它触发的 VBA 工作表中。
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H40")) Is Nothing Then
If IsEmpty(Range("H40")) Then
' do something
End If
End If
End Sub
推荐阅读
- javascript - 可以在反应中将类组件引用传递给子组件吗
- kubernetes - 如何从 Kubernetes 将机密写入 HashiCorp Valut 或 Azure Key Vault?
- java - 在静态块内的测试类中初始化字段后获取空指针
- python - 我从网上安装的 Python 模块的源代码
- mysql - 如何获取至少注册一次但最终状态未注册的学生列表?
- python - Seaborn columnwise violinplot
- c# - 构建一个简单的图书预订系统
- python - Selenium Select from dropdown element not found in heroku,但在本地找到
- react-native - React-Native FlatList 用大列表缓慢渲染一些项目
- c# - 执行 var = var + n 的快捷语法?