Ric*_*ion 3 excel vba excel-vba
我正在尝试替换ctrl + c,因此它只会复制受保护工作表上的可见单元格.试图解决这个问题我偶然发现了这个帖子(vba excel只复制按键ctrl + c上的可见单元格)
以下代码(由Siddharth-Rout建议)可用,但仅适用于未受保护的工作表:
Private Sub Workbook_Open()
Application.OnKey "^c", "Copy"
End Sub
Sub Copy()
Dim rng As Range
On Error GoTo Whoa
If Not Selection Is Nothing Then
Set rng = Selection.Cells.SpecialCells(xlCellTypeVisible)
rng.Copy
End If
LetsContinue:
Exit Sub
Whoa:
MsgBox Err.Description, vbCritical, "Error Number : " & Err.Number
Resume LetsContinue
End Sub
Run Code Online (Sandbox Code Playgroud)
我尝试取消保护,复制,然后重新保护,但它删除了副本.我需要保护最终的表格.任何帮助,将不胜感激.
啊! 从过去的爆炸:P
您需要在复制之前取消保护和保护.我也ActiveSheet用于演示目的.如果需要,将其更改为相关表.
这是你在尝试什么?
Sub Copy()
Dim rng As Range
Dim MyPassword As String
'~~> Change password as applicable
MyPassword = "Sid"
On Error GoTo Whoa
If Not Selection Is Nothing Then
ActiveSheet.Unprotect MyPassword
Set rng = Selection.Cells.SpecialCells(xlCellTypeVisible)
ActiveSheet.Protect MyPassword
rng.Copy
End If
LetsContinue:
Exit Sub
Whoa:
MsgBox Err.Description, vbCritical, "Error Number : " & Err.Number
Resume LetsContinue
End Sub
Run Code Online (Sandbox Code Playgroud)