Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

In Access 2010 - Using VBA, how can you tell if the Ribbon is being displayed

738 views
Skip to first unread message

Barry

unread,
Nov 22, 2013, 5:42:30 PM11/22/13
to
Hi,
Looking for code that will tell me if the ribbon is being displayed in Access 2010.
Thanks,
Barry

Ulrich Möller

unread,
Nov 22, 2013, 5:49:09 PM11/22/13
to
Public Function IsRibbonVisible() As Boolean
' Returns state of then ribbon bar:
' true := normal
' false := minimized

On Error Resume Next

IsRibbonVisible = CBool(CommandBars("Ribbon").Controls(1).Height > 100)

If Err.Number <> 0 Then Err.Clear
End Function

Not from me. I found it somewhere in the cloud but i can't remember ...

Ulrich

Barry

unread,
Nov 22, 2013, 6:35:25 PM11/22/13
to
Function does not appear to be working as expected.

I use the following code to hide or unhide the ribbon:
DoCmd.ShowToolbar "Ribbon", acToolbarNo
DoCmd.ShowToolbar "Ribbon", acToolbarYes

No matter what state the Ribbon is, visible or not visible, the function IsRibbonVisible always returns "True"

Any ideas?
Message has been deleted

Barry

unread,
Nov 22, 2013, 6:53:13 PM11/22/13
to
OK, got it - the function should be:

Public Function IsRibbonVisible() As Boolean
' Returns state of the ribbon bar:
' true := Visible
' false := Not Visible

On Error Resume Next

IsRibbonVisible = Application.CommandBars("Ribbon").Visible
' IsRibbonVisible = CBool(CommandBars("Ribbon").Controls(1).Height > 100)

Ulrich Möller

unread,
Nov 22, 2013, 10:44:47 PM11/22/13
to
Am 23.11.2013 00:41, schrieb Barry:
> Function IsRibbonVisible only returns "True" no matter if the Ribbon is visible or not.
>
> I am using the code below to hide or unhide the Ribbon:
> DoCmd.ShowToolbar "Ribbon", acToolbarNo
> DoCmd.ShowToolbar "Ribbon", acToolbarYes
>
> So need vba to tell me if the "Ribbon" is visible or not visible.
> Any ideas?
>

Hi Barry,

I've just tested the code with ACC2010(accdb) and it should work.

There is properly no easy way to get the visible status of the ribbon,
so the trick is, to construe the status from the control.height property.

The ribbon has to be enabled.
DoCmd.ShowToolbar "Ribbon", acToolbarYes
or DoCmd.ShowToolbar "Ribbon", acToolbarWhereApprop

Then toggle the Ribbon with <CTRL>+{F1} and get the height value of the
first control for each state

application.commandbars("Ribbon").Controls(1).height

You will get two different values. The boolean value is calculated then
with "controls(1).height > {your mean value}"

Maybe your mean value is different from mine?


Ulrich











Ulrich Möller

unread,
Nov 22, 2013, 11:00:47 PM11/22/13
to
Am 23.11.2013 00:53, schrieb Barry:
> OK, got it - the function should be:
>
> Public Function IsRibbonVisible() As Boolean
> ' Returns state of the ribbon bar:
> ' true := Visible
> ' false := Not Visible
>
> On Error Resume Next
>
> IsRibbonVisible = Application.CommandBars("Ribbon").Visible
> ' IsRibbonVisible = CBool(CommandBars("Ribbon").Controls(1).Height > 100)
>
>
> If Err.Number <> 0 Then Err.Clear
> End Function

Hi Barry,

Application.CommandBars("Ribbon").visible reflects the status after a
docmd.showtoolbar

IsRibbonVisible reflects the status wether the toolbar is minimized or not.

A little bit different.

Ulrich



0 new messages