Bug Report - vba CommandBars("Styles").Visible = True throws error - workaround using wdTaskPanesFormatting

User avatar
Charles Kenyon
4StarLounger
Posts: 596
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Bug Report - vba CommandBars("Styles").Visible = True throws error - workaround using wdTaskPanesFormatting

Post by Charles Kenyon »

[Edit :evilgrin: I have found a workaround using the TaskPanes collection wdTaskPanesFormatting will respond to a change in visible.]
oops
:hairout: This is a cross-post to a follow-up on the Word forum: https://eileenslounge.com/viewtopic.php ... 14#p308014 and my discussion on the Microsoft site: https://answers.microsoft.com/en-us/mso ... b9ee63955e I am posting here in hope of getting votes and comments on the Microsoft feedback portal. Any responses with suggestions for workarounds should be posted in the Word forum(https://eileenslounge.com/viewtopic.php ... 14#p308014). Thanks.

It is no longer possible to change the visible property of the Styles Pane using vba. Word throws an error.

I've filed a bug report in the feedback Portal.
https://feedbackportal.microsoft.com/fe ... 0d3a7a48db

I invite votes and comments in the Feedback Portal.
The vba command:

Code: Select all

application.commandbars("Styles").visible = True
worked fine through Word 2013, at least, and now throws an error. Runtime error -21474672259 (80004005) Unspecified error

It can also show error Method 'Visible' of object 'CommandBar' failed. -21474672259 (80004005)

This is to change display of the Styles Pane in Word.

Code: Select all

 ? application.commandbars("Styles").visible
in the immediate window will report True or False

Code: Select all

? application.commandbars("Styles").position
will give a position

The Visible Property can be changed with other commandbars.

See https://www.msofficeforums.com/word/509 ... 021-a.html

This is a bug and should be fixed

User avatar
SpeakEasy
4StarLounger
Posts: 536
Joined: 27 Jun 2021, 10:46

Re: Bug Report - vba CommandBars("Styles").Visible = True throws error - workaround using wdTaskPanesFormatting

Post by SpeakEasy »

Not sure it is a bug, though.

Firstly, Commandbars have been deprecated since about 2010

Secondly, .visible, .position and .width etc do work. IF .Enabled is true. And this is documented (perhaps badly, but documented, nevertheless).

And the behavior of .Enabled for builtin commands is also documented: it is under the control of the hosting application.

So, prior to 2013 it would apperar that .Enabled menubar was enabled by default for the Styles commandbar (opr atr least t4he application allowed VBA to modify it from the start).

In later versions it would appear that MS decided to let the applicatioin be more strict about this for some of the commandbars - and what isn't documented (as far as I can find) is exactly which of the builtin commandbars are locked down like this (once we manage to get Enabled set to True just once, then VBA seems to regain control). So it is the behaviour of .enabled that is at fault, but I'd suspect MS will argue that the behaviour is by design.

But let's see what response you get to the bug report (many, many years ago, when a large chunk of MS' online product support was still being done on Compuserve I got my own secret KB article raised plus a fix for a bug I'd raised with them that they repeatedly claimed was by design, so you never know ...)