Question

I have little experience in VBA, and am trying to make some minor adjustments to Word's default load settings.

When a user creates a document, I need the Styles Formatting Pane to open (I got this working fine), but I also need it to be docked on the right of the window. I've found snippets of code hinting at what is involved, but no solid example. It doesn't look that complicated, but I don't know what I'm doing wrong.

Here's what I've got so far:

Public Sub DisplayStylesMenu()

    ' Opens the Formatting task pane (Style window)
        Application.TaskPanes(wdTaskPaneFormatting).Visible = True

    ' Docks the Formatting pane on the right
        Application.CommandBars(wdTaskPaneFormatting).Position = msoBarRight

End Sub

This code runs when Word creates a new document. The formatting task pane appears as desired, but the position doesn't work. It breaks, and I get 'Runtime error 9: Subscript out of range'. Sometimes it also returns 'Index refers beyond the end of list', but this appears intermittently and I'm not sure what's causing it.

Apparently Word 07 loads the formatting pane docked to the right by default, but if a user has ever dragged it out so it floats over the document, this new position is remembered for next time. I need it to open docked every time.

Was it helpful?

Solution

When you refer to CommandBar object you need to use either its name of index number.

In you situation you need to change second line into this one:

Application.CommandBars("Styles").Position = msoBarRight

Which means that TaskPanes(wdTaskPaneFormatting) is CommandBars("Styles")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top