View Single Post
 
Old 07-08-2013, 08:20 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Windows XP Office 2007
Competent Performer
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default Macro to toggle outline level

I'd like to write a macro to toggle the outline level setting. That is, the heading level that is displayed in outline view. The macro would query the current outline level setting and based on that result, do something like this:
  • If the current View setting is "OutlineView", set the Outline Level to "ShowAllHeadings" and set the View to "NormalView".
  • Else set the View to "OutlineView" and the Outline Level to the level of the heading where the cursor is currently positioned. If the cursor is not on a heading, set the Outline Level to "Level 1".
Using the macro recorder, I captured the code to set the View and the Outline Level.
Code:
 
  ActiveWindow.ActivePane.View.Type = wdOutlineView
  ActiveWindow.View.ShowHeading 3
  ActiveWindow.View.ShowHeading 1
  ActiveWindow.View.ShowAllHeadings
  If ActiveWindow.View.SplitSpecial = wdPaneNone Then
    ActiveWindow.ActivePane.View.Type = wdNormalView
  Else
    ActiveWindow.View.Type = wdNormalView
  End If
I don't know how to query the heading level where the cursor is. Can someone help me with that?

Is there any way to get that code using the recorder?

I'd also appreciate any comments or suggestions on this macro.

Thanks
Reply With Quote