View Single Post
  #15   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default How to Disable/Enable hide entire row ability



You asked for code to hide/unhide rows and I gave it. I also gave
you

the 'design structure' info required to make that work for your
needs.

All you need to do now is decide how you want your project to work
and

code for that however you like. If you need more assistance please
post

back with sheet design info sufficient to provide the correct
help!<g


Hi Garry,

I feel you are missing the point of this thread. The code requested
was not to hide and show rows rather to disable the hide/show row
function only. This must be achievable since the sheet protection
can disable the function. Unfortunately along with other needed
functions. The sheet in question has no use for outlines or
summaries.

I already know that the show hide sheet function can be disabled
using the following

Application.CommandBars("Worksheet Menu
Bar").Controls("F&ormat").Controls("S&heet").Contr ols("&Unhide...").Enabled
= False

or a variant thereof

I am looking for a similar line that will do the same for show/hide
rows.

The other issue is that this is a shared workbook and as such you can
not alter protection properties once sharing has been set either
manually or through VBA.


Sorry if I've wasted your time! I admittedly do not work with 'shared
workbooks' and so I'm not familiar with the nuances associated with
that.

As for the code to disable hide/unhide.., what you example above is
what you want. You'll need to do same for each menu/commandbar that
gives UI access to those features. Also, be sure to undo changes to
those menus at shutdown so Excel's 'tlb' file isn't messed up when
Excel closes.

I normally build a delimited string of the menuitems so code uses a
simple loop. This string will contain value pairs like this...

commandbar=control

...where each value holds the name of the object. I use a global
variable as a 'flag' to set control state at startup/shutdown (ergo
open/close) so my projects know what AppMode they're in.

Dim gbShuttingDown As Boolean

In my Auto_Close sub...

Sub Auto_Close()
gbShuttingDown = True: ShutdownApp
End Sub

In my ShutdownApp sub...

Sub ShutdownApp()
'...
ManageMenus
RestoreExcelSettings
'...
End Sub

In the ManageMenus sub I set the Enabled property of controls to the
value of gbShuttingDown...

Sub ManageMenus()
'...
EnableDisable_BuiltinCtrls
'...
End Sub

Sample EnableDisable_BuiltinCtrls procedu

Const gsMenusToDisable$ _
= "Worksheet Menu Bar:F&ormat:&Row:&Unhide" _
& ",Worksheet Menu Bar:F&ormat:&Row:&Hide" _
& ",Worksheet Menu Bar:F&ormat:&Column:&Unhide" _
& ",Worksheet Menu Bar:F&ormat:&Column:&Hide" _
& ",Row:&Hide,Row:&Unhide" _
& ",Column:&Hide,Column:&Unhide"


Sub EnableDisable_BuiltinCtrls()
Dim vSz, vCtls, ctl As Object

On Error Resume Next '//can't toggle disabled context menus
For Each vSz In Split(gsMenusToDisable, ",")
vCtls = Split(vSz, ":")
Select Case UBound(vCtls)
Case Is = 1
CommandBars(vCtls(0)).Controls(vCtls(1)).Enabled =
gbShuttingDown
Case Is = 2

CommandBars(vCtls(0)).Controls(vCtls(1)).Controls( vCtls(2)).Enabled =
gbShuttingDown
Case Is = 3

CommandBars(vCtls(0)).Controls(vCtls(1)).Controls( vCtls(2)).Controls(vCtls(3)).Enabled
= gbShuttingDown
Case Is = 4

CommandBars(vCtls(0)).Controls(vCtls(1)).Controls( vCtls(2)).Controls(vCtls(3)).Controls(vCtls(4)).En abled
= gbShuttingDown
Case Is = 5

CommandBars(vCtls(0)).Controls(vCtls(1)).Controls( vCtls(2)).Controls(vCtls(3)).Controls(vCtls(4)).Co ntrols(vCtls(5)).Enabled
= gbShuttingDown
End Select
Next 'vSz
End Sub

...where at startup gbShuttingDown = False, thus sets Enabled to False.
At shutdown the variable reverts to True and so enables the controls.

Note that when working with some properties of builtin menus, errors
can be raised trying to change them and so are escaped. An example is
your sample code for Sheets; if there are no hidden sheets then that
menuitem is disabled and trying to change it throws an error.

You could just list the commandbar name once to shorten the string, but
then a 3rd delimiter would be required along with another variant to
contain the 3rd Split() and another For Each loop. I used to use a
worksheet table for this chore before I started using automated
instances of Excel wherein my menus and toolbars are the only one's
available. The table was constructed same as my commandbar table so was
easy to manage in a similar manner! This would be overkill for your
needs!<g

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion