gpt4 book ai didi

excel - 如何编写取消按钮以不清除表单?

转载 作者:行者123 更新时间:2023-12-04 22:25:28 26 4
gpt4 key购买 nike

我正在尝试创建一个“清除所有内容”按钮来清除我的表单并基本上为用户重置它。
我正在使用“vbOKCancel”按钮常量。我认为点击“取消”按钮会阻止此时的代码继续运行。但是当我点击“取消”按钮时,它会从我的表单中删除所有数据。

Private Sub CommandButton23_Click()

MsgBox "Are you sure you want to clear this entire form?", vbOKCancel

Dim aRange As Excel.Range
Set aRange = Range("E7").MergeArea

Dim bRange As Excel.Range
Set bRange = Range("E9").MergeArea

Dim cRange As Excel.Range
Set cRange = Range("E11").MergeArea

Dim dRange As Excel.Range
Set dRange = Range("E15").MergeArea

Dim eRange As Excel.Range
Set eRange = Range("E17").MergeArea

Dim fRange As Excel.Range
Set fRange = Range("E19").MergeArea

Dim gRange As Excel.Range
Set gRange = Range("E23").MergeArea

Dim hRange As Excel.Range
Set hRange = Range("N7").MergeArea

Dim iRange As Excel.Range
Set iRange = Range("N9").MergeArea

Dim jRange As Excel.Range
Set jRange = Range("O11").MergeArea

Dim kRange As Excel.Range
Set kRange = Range("Q11").MergeArea

Dim lRange As Excel.Range
Set lRange = Range("N13").MergeArea

Dim mRange As Excel.Range
Set mRange = Range("N15").MergeArea

Dim nRange As Excel.Range
Set nRange = Range("O17").MergeArea

Dim oRange As Excel.Range
Set oRange = Range("Q17").MergeArea

Dim pRange As Excel.Range
Set pRange = Range("N23").MergeArea

Dim xRange As Excel.Range
Set xRange = Range("G27").MergeArea

aRange.ClearContents
bRange.ClearContents
cRange.ClearContents
dRange.ClearContents
eRange.ClearContents
fRange.ClearContents
gRange.ClearContents
hRange.ClearContents
iRange.ClearContents
jRange.ClearContents
kRange.ClearContents
lRange.ClearContents
mRange.ClearContents
nRange.ClearContents
oRange.ClearContents
pRange.ClearContents
xRange.ClearContents

End Sub

最佳答案

处理 MsgBox 的结果:

Private Sub CommandButton23_Click()
Dim response As VbMsgBoxResult
response = MsgBox("Are you sure you want to clear this entire form?", vbOKCancel)

If response = vbCancel Then Exit Sub

...
End Sub

关于excel - 如何编写取消按钮以不清除表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58191139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com