Suprimare comenzi Excel

Închis
zvonacfirst
Mesaje: 105
Membru din: Mie Feb 19, 2014 10:41 pm

Suprimare comenzi Excel

Mesaj de zvonacfirst » Mie Noi 29, 2017 2:04 pm

Salut.

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
Nu aveţi permisiunea de a vizualiza fişierele ataşate acestui mesaj.

zvonacfirst
Mesaje: 105
Membru din: Mie Feb 19, 2014 10:41 pm

Re: Suprimare comenzi Excel

Mesaj de zvonacfirst » Mie Noi 29, 2017 2:47 pm

Am rezolvat problema.
Am pus in modul prima linie Option Private Module iar codurile le-am lasat publice.
Voiam ca macrourile sa nu fie vizibile si sa nu poata fi rulate independent.
Nu stiu daca este singura solutie dar functioneaza.
Nu aveţi permisiunea de a vizualiza fişierele ataşate acestui mesaj.

Închis

Înapoi la “Visual Basic for Application (VBA) cu Excel - Intrebari tehnice”