NGusCar
NGusCar

Reputation: 61

Navigation Pane in Word 2016: VBA code to force collapsed view of headings

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?

Upvotes: 6

Views: 1763

Answers (3)

Jedi-X
Jedi-X

Reputation: 21

Looking for a similar answer myself and this seems like a start:

Charles Kenyon Volunteer Moderator Replied on June 6, 2023 Report abuse You can activate/hide the Navigation Pane through vba, but not choose the display to Pages. I ksov of no way to manipulate this except manually.

Application.TaskPanes(wdTaskPaneNav).Visible = True

You can control the position and width using:

Application.CommandBars("Navigation").Position = msoBarLeft Application.CommandBars("Navigation").Width = 350 ' in pixels msoBarLeft is the default position.

This will also respond to msoBarFloating and msoBarRight.

Volunteering to "pay forward" the help I've received in the Microsoft user community.

Charles Kenyon Sun Prairie, Wisconsin wordfaq[at]addbalance[dot]com

Legal site: https://addbalance.com

Source: answers.microsoft.com/.../vba-word-365-how-to-use-vba-macro-to-auto-open...

Upvotes: 0

Hauke
Hauke

Reputation: 41

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

Upvotes: 4

I say Reinstate Monica
I say Reinstate Monica

Reputation: 518

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.

Upvotes: 3

Related Questions