-
EnableMenuItem function help
hi,
i found an example to disable the cut copy past commands ( http://www.vbaexpress.com/kb/getarticle.php?kb_id=373 ). so it uses the
Call EnableMenuItem(21, Allow) ' cut
Call EnableMenuItem(19, Allow) ' copy
Call EnableMenuItem(22, Allow) ' paste
Call EnableMenuItem(755, Allow) ' pastespecial
and other code.........
so, if i want to disable the save and save as command so which id should i use instead of the Highlighted numbers ?
or any of you have the sample workbook that has the save and save as command are disabled (from file>save , file > save as , the sav buttons on toolbar and the ctrl + s method ) and also notice one thing that i just want to disable these normal ways ONLY . A user can save that workbook using a macro(is allowed ) so any way ?????????
-
&New...: 18
&Open...: 23
&Close: 106
&Save: 3
Save &As...: 748
Save as Web Pa&ge...: 3823
Save &Workspace...: 846
Searc&h...: 5905
Ch&eck Out: 6127
Ch&eck In: 6128
We&b Page Preview: 3655
Page Set&up...: 247
Prin&t Area: 30255
Print Pre&view: 109
&Print...: 4
Sen&d To: 30095
Propert&ies: 750
Acquire Text...: 1
Acquire Text Settings...: 1
E&xit: 752
I got this with
[vba]
Dim oCtl As CommandBarControl
For Each oCtl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print oCtl.Caption & ": " & vbTab & vbTab & oCtl.ID
Next oCtl
[/vba]
-
-
In the Thisworkbook code module
[VBA]
Option Explicit
Private Sub Workbook_Open()
With Application
.OnKey "^{s}", "DontSaveMsg"
.VBE.CommandBars("File").Controls("Save " & ActiveWorkbook.Name).Enabled = False
With .CommandBars("File")
.Controls("Save").Enabled = False
.Controls("Save As...").Enabled = False
End With
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Application
.VBE.CommandBars("File").Controls("Save " & ActiveWorkbook.Name).Enabled = True
With .CommandBars("File")
.Controls("Save").Enabled = True
.Controls("Save As...").Enabled = True
End With
End With
End Sub
[/VBA]
In a standard code module
[VBA]
Option Explicit
Private Sub DontSaveMsg()
MsgBox "Save is disabled"
End Sub
[/VBA]
You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you
The major part of getting the right answer lies in asking the right question...
Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.
-
hi xld,
how to use this ?
Dim oCtl As CommandBarControl
For Each oCtl In Application.CommandBars("Worksheet Menu Bar").Controls("File").Controls
Debug.Print oCtl.Caption & ": " & vbTab & vbTab & oCtl.ID
Next oCtl
-
That is just a simple bit of code that produced the list I gave in my previous response.
Put it in a macro and run it. You can change File to Edit, Tools, etc. to get the other ids.
-
hi xld,
sorry but i can't understand. I paste that code in a macro and run it . But it gives nothing output ! I'm surely doing some mistake . Please point me to that .
-
It outputs to the immediate window in the VBIDE, that is what Debug.Print does.
-
xld,
oh i got it ! thankyou ...............
-
so can i change its caption ? (like file>new to file>new1)??
-
-
hi xld,
By using that macro , i can disable the save save as buttons in office 2003 . but when i tried it in office 2007 that did'nt work ! (save button was enabled!)
so , wht's about office 2007 ? (in office 2007 there are no menus like file , edit... but there is a office button at the titlebar so , if posssible , i want to disable the whole office button. I tried using your code to get those ids but .. no success ! )
any idea ?
Regards ,
dansam
-
Office 2007 is obviously different.
Off the top I have no idea if you can disable the Office button, and if so how. If I get a minute, I will see what I can see, but knowing that the ribbon is not exposed in the same way that commandbars are, I wouldn't be surprised if you can't do it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules