Log in

View Full Version : Disable command in ribbon



Tommy
12-06-2011, 03:52 PM
Ok here is my issue(s).

I have code in a Word doc that works like it is supposed to in 2003.:thumb

What I am doing is making it where the user can only use the doc that is open, they cannot open, new, save, save as, other docs, nor can they close the one that is open. I want them to pick the close application X in the upper right hand corner. This way I can do what needs to be done and let them (the user) go about their merry way. So in short I have a great little world. :cloud9:

Then comes along Word 2010. Everything works until I get to the ribbon, I don't want a custom ribbon I just want to disable the open, new, save, and save as options. I have aquired a whole lot of information and it will takes me weeks to read it all and a couple of more months to digest it. That is if I can keep it down.:rotlaugh:

So I am humblely asking for a handout. A quick pointer to something that will lead me to what I would like to do. I wrote this in 2003 in 45 min, I have spent 1 1/2 days looking for information on how to do this without creating a cutom ribbon, or using VS 2010.

I am almost at the point of opening up VS 2010 and just writing a flipping front end. Probally quicker and I would have more control and will not have to disable a few command.

If you have made it this far thanks for taking the time to read it and possibly help.:beerchug:

macropod
12-06-2011, 10:48 PM
So how did you handle it for Word 2007? You might find it worthwhile checking out the various threads here: http://www.vbaexpress.com/forum/forumdisplay.php?f=96

Tommy
12-07-2011, 07:20 AM
So how did you handle it for Word 2007?
Maybe I should have said that I am coding in 2003 and the users have 2010. So to answer your question I didn't. :rofl:


You might find it worthwhile checking out the various threads here: http://www.vbaexpress.com/forum/forumdisplay.php?f=96
I did that before I posted. Everything I saw had something to do with the CustomUI program. I have also done a google search and came up with a lot of information with a list of links and such. But most of them want to use and add-in or a template.

So I guess the answer is go home and code it in Word 2010 and figure out the schema.:banghead:

btw a lot of good information here: http://gregmaxey.mvps.org/Customize_Ribbon.htm

Paul_Hossler
12-10-2011, 05:28 PM
If you want to use a docm, you can overload commands with your own

For example, if this is in the .docm file, then when the user tries to open a file, it's your sub that runs



Sub FileOpen()
MsgBox "No --- you can't do this"
End Sub


Paul

Tommy
12-12-2011, 07:04 AM
Thanks Paul, That may be a way around my issue for coding in 2003 and working in 2010. I need to find out when I get upgraded, that would make a big difference I am beginnin to think I am the only one with '03 so I need to code at home and bring it to work. :(

jqdx27
12-12-2011, 11:35 PM
To disable copy and paste command in 2003, you can install this code into the workbook:


Option Explicit

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

Private Sub Workbook_Activate()
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

Private Sub Workbook_BeforeClose(Cancel As Boolean)
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

Private Sub Workbook_Deactivate()
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

Private Sub Workbook_Open()
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
Open up your workbook.
Get into VBA (Press Alt+F11)
Double click on (This WorkBook) in the left-hand pane
Copy and Paste in the code (given below)
Save your sheet.


so now when the sheet is opened, the copy and paste functions will be disabled. When you close the sheet, they will be re-enabled. but Unfortunately, if the user selects "disable macros" when opening the sheet, they won't work...the sheet will open with cut/copy/paste still working.