You can create your own copy routine, that does not store the whole cell, but only its value in the clipboard:
Sub OwnCopy()
Dim DataObj As New MSForms.DataObject
DataObj.SetText ActiveCell.Value 'depending what you want, you could also use .Formula here
DataObj.PutInClipboard
End Sub
To be able to compile the macro, you need to include "Microsoft Forms 2.0 Object Library" as a reference (in the Visual Basic editor, go to Tools->References and browse %windir%\system32
for FM20.dll
1).
您现在可以使用默认的运行宏对话框将此宏分配给另一个快捷方式(例如Ctrl- ) Shift,C甚至可以通过执行来覆盖Ctrl。但是,我不建议覆盖-因为除了粘贴到编辑器之外,您很可能希望使用通常与它一起复制的所有其他信息。cApplication.OnKey "^c", "OwnCopy"
Ctrlc
要使其永久化,只需将宏存储在您的个人工作簿中。
如果您想要一个更复杂的复制例程,它还可以处理多个单元格/选择区域,请使用以下代码:
Sub OwnCopy2()
Dim DataObj As New MSForms.DataObject
Dim lngRow As Long
Dim intCol As Integer
Dim c As Range
Dim strClip As String
Const cStrNextCol As String = vbTab
Const cStrNextRow As String = vbCrLf
With Selection
If Not TypeOf Selection Is Range Then
On Error Resume Next
.Copy
Exit Sub
End If
If .Areas.Count = 1 Then
For lngRow = 1 To .Rows.Count
For intCol = 1 To .Columns.Count
strClip = strClip & _
Selection(lngRow, intCol).Value & cStrNextCol
Next intCol
strClip = Left(strClip, Len(strClip) - Len(cStrNextCol)) _
& cStrNextRow
Next lngRow
Else
For Each c In .Cells
strClip = strClip & c.Value & vbCrLf
Next c
End If
strClip = Left(strClip, Len(strClip) - Len(cStrNextRow))
DataObj.SetText strClip
DataObj.PutInClipboard
End With
End Sub
1实际上,此文件存在于%ProgramFiles%\Microsoft Office\root\vfs\System
- Office 使用一些虚拟化技巧使其出现在它所在的位置。