vbapowerpointcommandbar

Powerpoint - VBA - Run Application CommandBars


I want to create a macro which allows, once an object is selected, to open the associated CommandBar.

I wrote the following which works sometimes, but not everytime - it does not work the first time. and I do not understand why. I have to manually do a right click and select the "Height and position" option to run it for the first time and then everything works - the formatting pane is displayed.

Do you have any clues to avoid the right click part?

Sub Bars ()
  Application.CommandBars("Format Object").Visible = True
End Sub

This is Office 2016.

Outpout Other code tested:

Sub Bars ()
  On Error GoTo Out
  Dim cmd As CommandBar
  For Each cmd In Application.CommandBars
    cmd.Enabled = True
  Next
  If Application.CommandBars("Format Object").Visible = True Then
    Application.CommandBars("Format Object").Visible = False
  Else
    Application.CommandBars("Format Object").Visible = True
  End If
Out:
  Exit Sub
End Sub

Solution

  • Quite possibly, the reason the code is not working as expected is because PowerPoint 2016 (as all versions for the last 12 years or so) no longer uses CommandBars for the user interface. It can work, but it's better to use the Ribbon whenever possible.

    In order to trigger a built-in command, it's possible to use the idMSO "name" of the command. A complete list of these commands can be downloaded here.

    Searching the list for Format turns up the idMSO ObjectFormatDialog. Testing on my system using the following line displays the Format Shape task pane:

    Application.CommandBars.ExecuteMso("ObjectFormatDialog")
    

    The "Mso" methods are the only things CommandBars are used for, these days...