在Excel中运行宏时,我试图添加警告消息。
警告消息是在运行下面的代码以清除单元格之前,提供一个“取消”选项。
当尝试在下面的对话框中添加一个消息框时,鼓励用户从功能区激活该宏,我似乎无法使其正常运行。
工作表已锁定,因此只有未锁定的单元格才更清晰。
任何人都可以协助启用这两个步骤吗?
Sub Glazing_ClearContents(rib As IRibbonControl)
Dim rng As Range
Dim C As Variant
Set rng = Sheets("Glazing_Systems").Range("C12:I42")
For Each C In rng
If C.Locked = False Then
C.ClearContents
Else
End If
Next C
End Sub
答案 0 :(得分:1)
在询问用户是否要使用宏时,使用以下代码没有发现任何麻烦
question = "Are you sure you want to run this Macro?"
If MsgBox(question, vbYesNo + vbQuestion) = vbYes Then
''''' Place your code to be executed if you clicked yes
else
'''''' Place your code to be executed if you clicked no
end if
希望这对您有帮助!
答案 1 :(得分:1)
Option Explicit
Sub test()
Dim Continue As String
Continue = MsgBox("Are you sure you want to clear cells?", vbCritical + vbYesNo, "Attention")
If Continue = vbYes Then
Else
End If
End Sub