Am nevoie sa suprim unele dintre comenzile uzuale din excel si am cautat o solutie.
Aceste lucru imi este necesar pentru a bloca in special Cut, Copy si Paste pentru acele cells care pot fi editate (sunt unlocked), motivul fiind ca am unii colegi care sunt utilizatori foarte elementari de Excel si s-a intamplat sa produca pierderi importante fara intentie.
Am cautat o solutie care sa imi permita sa dezactivez sau sa activez comenzile respective in functie de necesitati. Eu ca administrator vreau sa le am disponibile dar sa fie indisponibile pentru ceilalti useri.
Codul urmator face ce vreau dar am o problema:
- am doua coduri: CutsOff si CutsOn
- rulate independent merg foarte bine, indiferent daca sunt Private sau nu
- daca macrourile sunt Private nu le pot rula cu functia Call integrata in codul unui commandbutton, de exemplu.
Nu as vrea sa le las publice.
O sugestie? Multumesc.
Atasez un fisier excel pentru exemplificare.
Codul utilizat este urmatorul (este pus intr-un modul standard):
Cod: Selectaţi tot
Private Sub CutsOff()
AllowCuts False
End Sub
-------------------------------------------------------------
Private Sub CutsOn()
AllowCuts True
End Sub
-------------------------------------------------------------
Private Sub AllowCuts(bEnable As Boolean)
Dim oCtls As CommandBarControls, oCtl As CommandBarControl
Set oCtls = CommandBars.FindControls(ID:=21) 'Cut
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=19) 'Copy
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=6002) 'Paste button
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=22) 'Paste in Edit menu
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=755) 'Paste Special...
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
Set oCtls = CommandBars.FindControls(ID:=847) 'Delete
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
''Disable Tools, Options so D&D cannot be restored
Set oCtls = CommandBars.FindControls(ID:=522)
If Not oCtls Is Nothing Then
For Each oCtl In oCtls
oCtl.Enabled = bEnable
Next
End If
With Application
.CellDragAndDrop = bEnable
If bEnable Then
.OnKey "^x"
.OnKey "+{Del}"
.OnKey "^c"
.OnKey "^v"
Else
.OnKey "^x", ""
.OnKey "+{Del}", ""
.OnKey "^c", ""
.OnKey "^v", ""
End If
End With
End Sub