以下解决方案将“删除行”自定义菜单项添加到行上下文菜单。右键单击行选择器时看起来像这样。它会在实际删除行之前提示用户确认行删除...
在项目级模块中,添加以下子例程...
Public Sub DeleteRow()
If MsgBox("Are you sure?", vbOkCancel, "Confirm Delete") = vbOk Then
Selection.EntireRow.Delete
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
在工作表代码模块中,添加以下子例程...
Private Sub Worksheet_Activate()
'reset to standard context menu before adding new option
Application.CommandBars("Row").Reset
'add custom row deletion call
With Application.CommandBars("Row").Controls.Add
.Caption = "Delete Row"
.Style = msoButtonCaption
.OnAction = "DeleteRow"
End With
End Sub
Private Sub Worksheet_Deactivate()
'get rid of the customization when you're done with this sheet
Application.CommandBars("Row").Reset
End Sub
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
645 次 |
| 最近记录: |