5

I am trying to write a VBA macro that runs when opening a .docx document. I want it to force the display of the Navigation Pane and then force all of the headings (any level) to display in collapsed mode. I am trying to get the code for the Collapse command using the macro recorder.

All I have when I record the macro is:

ActiveWindow.DocumentMap = True

Right-clicking on a heading in the Navigation Pane and collapsing does not record a code line. Is there a VBA method for this event?

braX
  • 11,506
  • 5
  • 20
  • 33
NGusCar
  • 51
  • 3
  • I believe this is NOT supported in the Word object model. Generally, no commands are exposed for Task Pane content of any kind. Built-in task panes can only be shown, hidden or positioned. – Cindy Meister Apr 30 '19 at 16:00

2 Answers2

3

I "solved" this requirement for myself by means of an AutoHotKey script, which just sends the necessary mouse click and subsequent key strokes. Not beautiful, but it works most of the times. Kind regards, Hauke

Hauke
  • 31
  • 5
2

As of this writing in 2019, this is not possible through VBA. It's been asked for from Microsoft for a long time.

As originally suggested in this Microsoft forum post, the quickest way to collapse all of the headings in the Navigation pane is to right-click one of the headings and click Collapse All. Obviously this is not an automated/macro-based solution, but it's all we have until Microsoft exposes the task panes through the VBA object model.

  • I made a uservoice request for such a feature to the Word developer team. Vote for it here: https://word.uservoice.com/forums/304924-word-for-windows-desktop-application/suggestions/41841436-start-navigation-pane-collapsed – Tomas Nov 03 '20 at 13:43