Dave H.? Disabling Commandbar buttons/controls via VBA?

L

Legacy 98055

Guest
Hi everyone!
Was trying to help out a poster,
see Topic: http://www.mrexcel.com/board/viewtopic.php?topic=4219&forum=2&7
if necc.

example 1:
Application.CommandBars("Standard").Controls _
("Print Preview").Enabled = False
Application.CommandBars.Controls

Hierarchy Summary:
Application.CommandBars.Controls

example 2:
Application.CommandBars("Worksheet Menu Bar").Controls _
("File").Controls("Print Preview").Enabled = False

Hierarchy Summary:
Application.CommandBars.Controls.Controls



This code for example 1 works fine:
Disables any control which begins with the Caption "Print"

Sub DisableCommandBarControl()
Dim cb As CommandBar
Dim bc As CommandBarControl

For Each cb In CommandBars
For Each bc In cb.Controls
If Left(bc.Caption, 5) = "Print" Then _
bc.Enabled = False
Next
Next

End Sub


But I could not for the life of me figure out the code for
example 2?

Anyway, I would like to know how to dig deeper here.

Thanks!
Tom
This message was edited by TsTom on 2002-04-10 05:52
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Just reviving this post.
I saw a few browsers here presently that might lend some help.
Thanks
Tom
 
Upvote 0
Hi Tom

Do you want:

Code:
 Application.CommandBars("Worksheet menu bar").Controls("File").Controls("Print Pre&view").Enabled = False

????


If the user wishes to prevent Printing while in a specific Workbook,a better option maybe:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Sorry, no printing"
Cancel = True
End Sub
 
Upvote 0
I agree with you on the simpler code, but the lady seemed bent on disabling her icon buttons and menu items.

I was trying to figure out the looping code for example two.
I could not figure out the syntax.

The first example would disable every control on a commandar that started with "Print"

But the second was a contol embedded in another control

Application.CommandBars("Standard").Controls _
("Print Preview").Enabled = False
Application.CommandBars.Controls

Hierarchy Summary:
Application.CommandBars.Controls


CommandBars("Worksheet Menu Bar")
Controls("File")
Controls("Print Preview")

See what I mean?

My looping code would disable "Print" on the commandbar but not "Print" on the filemenu??

Thanks,
Your overcomplicated posting friend,
Tom
 
Upvote 0
What about Ctrl P or File, Page Setup, Print? The Workbook_BeforePrint is a far neater and more effective way of disabling printing and previewing - as suggested by Dave H here and by me in the original post.

Regards,
Dan
This message was edited by dk on 2002-04-10 06:36
 
Upvote 0
I agree with you as well!
I was just trying to gain the knowledge of code access to these controls embedded in other controls. I could not figure it out.
The lady got what she wanted, this is just a question that arose for myself in the proccess of trying to help her get what she wanted.
Not really important.
Thanks guys
Tom
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top