Macro disable cutfunction

J

Jonsson

Hi,all

I want a macro that disable the function "cut" in a woorkbook and I found
this macro down below, in a previous thread.
But it doesnt work for me.
I get an error at "Application.commandbars("Worksheet
MenuBar").Controls("Edit").Controls("Cut").enabled = False/True"
when I try to open/close the workbook.
I have put this into a module.
Could it be because I have a swedish version of MSOffice?

Thanks in advance

//Thomas

Sub Auto_Open()
Application.Onkey "^x",""
Application.Onkey "^+x",""
Application.commandbars("Worksheet
MenuBar").Controls("Edit").Controls("Cut").enabled = False
Application.commandbars("Cell").Controls("Cut").enabled = False
Application.commandbars("Worksheet
MenuBar").Controls("Edit").Controls("Paste").enabled = False
Application.commandbars("Cell").Controls("Paste").enabled = False
Application.Commandbars("Toolbar List").Enabled = False
End Sub

Sub Auto_Close()
Application.Onkey "^x"
Application.Onkey "^+x"
Application.commandbars("Worksheet
MenuBar").Controls("Edit").Controls("Cut").enabled = True
Application.commandbars("Cell").Controls("Cut").enabled = True
Application.commandbars("Worksheet
MenuBar").Controls("Edit").Controls("Paste").enabled = True
Application.commandbars("Cell").Controls("Paste").enabled = True
Application.Commandbars("Toolbar List").Enabled = True
End Sub
 
S

SOS

Johnsson,

Hi. From looking at your code it would appear that you want to disable
both "Cut" and "Paste" from the menubar and from right-clicking in the
cell.

I trimmed your code and it seems to work for me

Regards

Seamus


Sub Auto_Open()
With Application
..OnKey "^x", "" 'disables Ctrl plus x for cut
..OnKey "^v", "" 'disables Ctrl plus v for paste
End With
With Application.CommandBars("Edit")
..Controls("Cut").Enabled = False
..Controls("Paste").Enabled = False
End With
With Application.CommandBars("Cell")
..Controls("Cut").Enabled = False
..Controls("Paste").Enabled = False
End With
End Sub

***********************************************

Sub Auto_Close()
With Application
..OnKey "^x" 'enables Ctrl plus x for Cut
..OnKey "^v" 'enables Ctrl plus v for Paste
End With
With Application.CommandBars("Edit")
..Controls("Cut").Enabled = True
..Controls("Paste").Enabled = True
End With
With Application.CommandBars("Cell")
..Controls("Cut").Enabled = True
..Controls("Paste").Enabled = True
End With
End Sub
 
L

Loomah

Hi
This is another option that will disable all occurrences of CUT apart from
CTRL+X which you have covered anyway

Sub Find_Disable_Commands()
Dim myControls As CommandBarControls
Dim ctl As CommandBarControl
Set myControls = CommandBars.FindControls _
(Type:=msoControlButton, id:=21) '21=cut
For Each ctl In myControls
ctl.Enabled = False 'or true!!
Next ctl
End Sub

If you also need to disable paste the ID is 22. If you need to disable Copy
the ID is 19. I have no proof but this should work in any language, I would
have thought so anyway!

;-)
 

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