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")