#1
|
||||
|
||||
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 |
#2
|
||||
|
||||
Hi Jennifer,
Other than adding a bit more structure and simplifying the code a bit, the code seems fine. Code:
Sub MyOutlineLevel() Dim ParOutline As Long ParOutline = Selection.Paragraphs(1).OutlineLevel With ActiveWindow.View Select Case .Type Case wdNormalView, wdPrintView If ParOutline <> 10 Then .ShowHeading ParOutline .Type = wdOutlineView Case wdOutlineView .ShowAllHeadings .Type = wdNormalView Case Else End Select End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
I did some more testing including a macro recording:
Code:
' ActiveWindow.ActivePane.View.Type = wdOutlineView ' ActiveWindow.View.ShowHeading 1 ' ActiveWindow.View.ShowHeading 2 ' ActiveWindow.View.ShowHeading 9 ' ActiveWindow.View.ShowAllHeadings ' If ActiveWindow.View.SplitSpecial = wdPaneNone Then ' ActiveWindow.ActivePane.View.Type = wdNormalView ' Else ' ActiveWindow.View.Type = wdNormalView ' End If In any case, after I was able to split the screen, my macro seems to work properly in either pane. Do I need to worry about that extra test? |
#4
|
||||
|
||||
Quote:
ActiveWindow.Split The ActiveWindow.View.SplitSpecial property is for controlling whether headers/footers, etc. are displayed in a separate pane.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Querying the paragraph outline level | Jennifer Murphy | Word VBA | 1 | 01-18-2014 01:20 AM |
Paragraph Outline level changes | bburns | Word | 10 | 07-16-2013 02:34 AM |
Macro to toggle outline level | Jennifer Murphy | Word VBA | 0 | 07-08-2013 08:20 AM |
How to have the words existing in the same Outline Level to be in the Table of Conten | Jamal NUMAN | Word | 1 | 04-15-2011 06:26 PM |
Outline level to Body Text | dariober | Word | 0 | 08-23-2010 02:54 AM |