|
本帖最后由 cgx5871 于 2018-7-2 15:01 编辑
想做一个, 快捷键Ctrl+v粘贴时.
如果工作表是筛选状态. 且复制的单元格---可见单元格, 非连续性.
一. 快捷键Ctrl+v粘贴时, 弹出粘贴选项菜单---,
1. 正常粘贴,
2. 可见单元格粘贴. (更完美一点, 就是把可见性粘贴, 放在Excel自带的右下角 "+"号 的粘贴选项中
二. 右键菜单时, 自动在右键菜单添加一个....<可见单元格粘贴>.
三. 添加快捷,Alt+v=可见单元格粘贴.
菜单要怎么传递参数?
- Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
- Application.CommandBars("cell").Reset '删除所有右键菜单,避免重复添加
- With Application.CommandBars("cell").Controls.Add(, , , 3, 1)
- .FaceId = 22 '粘贴图标
- .OnAction = "'PasteVisible""" & (SelectionVisible) & """'"
- .Caption = "粘贴(可见单元格)(Alt+V)"
- .Style = msoButtonIconAndCaption
- End With
- End Sub
复制代码- Public SelectionVisible As Range
- Sub CopyVisible()
- Selection.Copy
- If InStr(1, Selection.SpecialCells(xlCellTypeVisible).Address, ",") > 0 Then '判断是否连续区域
- Set SelectionVisible = Selection.SpecialCells(xlCellTypeVisible) '取出可见区域
- Else
- Set SelectionVisible = Nothing
- End If
- End Sub
- Sub PasteVisible()
- If SelectionVisible Is Nothing Then
- Selection.Paste
- Else
- MsgBox "可见单元格粘贴"
- End If
- End Sub
复制代码
|
|