Option Explicit
Const mszBarName As String = "cell"
Const mszMenuCaption As String = "Paste &Formulas"
Sub CreateFormulaSpecial()
' Add a custom menu item
Const szMenuAction As String = "CstmPasteFormulas"
Const lMenuFaceID As String = 31
InitSKeys
DeleteFormulaSpecial
Dim cBar As CommandBar
Set cBar = Application.Commandbars(mszBarName)
On Error Resume Next
With cBar
.Controls(mszMenuCaption).Delete
.Controls("&Paste").Delete
.Controls("Paste &Special...").Delete
With .Controls.Add(msoControlButton, , , 3, True)
.Caption = mszMenuCaption
.OnAction = szMenuAction
.FaceId = lMenuFaceID
End With
End With
Set cBar = Nothing
End Sub
Sub DeleteFormulaSpecial()
' Remove the custom menu
On Error Resume Next
With Application
'.Commandbars(mszBarName).Controls(mszMenuCaption).Delete
.Commandbars(mszBarName).Reset
.OnKey "^v", ""
End With
On Error GoTo 0
End Sub
Sub CstmPasteFormulas()
On Error Resume Next
If Not Selection.Locked Then
Selection.PasteSpecial xlFormulas
Else
MsgBox "You cannot paste into protected cells", 64
End If
On Error GoTo 0
End Sub
Sub InitSKeys()
Application.OnKey "^v", "CstmPasteFormulas"
End Sub