Protecing cells

  • Thread starter Thread starter mcrilly
  • Start date Start date
M

mcrilly

Hi,

I'm just wodnering if there is any way at all to protect a cell in suc
a way that users are unable to copy and paste data in to the cell fro
the system clipboard? I don't want to lock the cell, just protect i
from "outside" data as this usually ruins the formatting of the cell.

Any ideas
 
This could be a possible solution:

Run DisableCutAndPaste from a suitable event procedure
(e.g. Workbook_Open or Worksheet_Activate) and EnableCutAndPaste
from another (e.g. Workbook_Close or Worksheet_Deactivate).

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

===========

Fable
 
Back
Top