copy & paste from other worksheet - but not allow to cut

G

Guest

I have a formatted area I try to keep right formatted! I have tried to use
conditional formatting, but when you paste a cell from an other worksheet,
that format follow.

I have tried to use the frequent suggested funktion DisableCutAndPaste
below, but it doesn't allow me to copy & paste! I tried to disable some of
the controls, but can't find it to work. Please help me! I enclose the whole
code for the specific sheet (Blad101) if there are any of the other subs who
cause any trouble.

Thank you for any help!

Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
Call DisableCutAndPaste

If Blad101.Range("O13") = 1 Then
Call GomTommaRader_B_4_125 ' hide rows sub if
checkbox = 1

ElseIf Blad101.Range("O13") = 0 Then
Call TaFramRad_Alla 'unhide rows
if checkbox = 0
End If

ActiveSheet.Protect AllowFormattingCells:=False
ActiveSheet.EnableSelection = xlUnlockedCells


End Sub
Private Sub Worksheet_Deactivate()
Call EnableCutAndPaste

End Sub

Sub DisableCutAndPaste()
EnableControl 21, False ' cut
'EnableControl 19, False ' copy
'EnableControl 22, False ' paste
'EnableControl 755, False ' pastespecial
'Application.OnKey "^c", ""
'Application.OnKey "^v", ""
'Application.OnKey "+{DEL}", ""
'Application.OnKey "+{INSERT}", ""
Application.CellDragAndDrop = False
End Sub

Sub EnableCutAndPaste()
EnableControl 21, True ' cut
EnableControl 19, True ' copy
EnableControl 22, True ' paste
EnableControl 755, True ' pastespecial
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "+{DEL}"
Application.OnKey "+{INSERT}"
Application.CellDragAndDrop = True
End Sub

Sub EnableControl(Id As Integer, Enabled As Boolean)
Dim CB As CommandBar
Dim C As CommandBarControl
For Each CB In Application.CommandBars
Set C = CB.FindControl(Id:=Id, recursive:=True)
If Not C Is Nothing Then C.Enabled = Enabled
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top