View Single Post
 
Old 01-18-2014, 01:32 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 need a macro to toggle the document outline level so I can more easily move document sections around. The macro would query the document layout and the paragraph outline level.

Here's the logic:

If the document is in Normal (or Page) view and the cursor is on a heading, the macro would switch to outline view and set the document outline view level to the paragraph outline level so that it could be moved up or down amongst its peers using the Alt+Shift+Up/Down shortcut.

If the document is in Outline view, the macro would set the document outline view to "All" and switch back to Normal layout.

For any other combination, the macro would do nothing.

Here's the code, which seems to work. Does anyone have any comments:

Code:
Sub MyOutlineLevel()

Dim DocLayout
Dim ParOutline

DocLayout = ActiveWindow.View
ParOutline = Selection.Paragraphs(1).OutlineLevel

Select Case DocLayout
  Case wdNormalView, wdPrintView
    If ParOutline = 10 Then
      Exit Sub
    Else
      ActiveWindow.View.ShowHeading ParOutline
    End If
    ActiveWindow.View.Type = wdOutlineView
  Case wdOutlineView
    ActiveWindow.View.ShowAllHeadings
    ActiveWindow.View.Type = wdNormalView
  Case Else
    Exit Sub
End Select

End Sub
Reply With Quote