Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2014, 01:32 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Macro to toggle outline level Windows XP Macro to toggle outline level Office 2007
Competent Performer
Macro to toggle outline level
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 232
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
  #2  
Old 01-22-2014, 07:11 PM
macropod's Avatar
macropod macropod is offline Macro to toggle outline level Windows 7 32bit Macro to toggle outline level Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,489
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

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]
Reply With Quote
  #3  
Old 01-22-2014, 08:36 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Macro to toggle outline level Windows XP Macro to toggle outline level Office 2007
Competent Performer
Macro to toggle outline level
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 232
Jennifer Murphy is on a distinguished road
Default

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
The recorded code has the extra test for what I assume is a split pane. I tried to test my macro with a split pane, but didn't seem to have that option enabled. After a bit of poking around, I discovered that split pane is not available if the Document Map is open (sigh). Do the MSFT engineers lie awake at night thinking about ways to make special cases in their code?

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?
Reply With Quote
  #4  
Old 01-22-2014, 11:22 PM
macropod's Avatar
macropod macropod is offline Macro to toggle outline level Windows 7 32bit Macro to toggle outline level Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,489
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Quote:
Originally Posted by Jennifer Murphy View Post
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?
I'm not sure what you mean here. If all you're after is a split screen, you can use:
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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to toggle outline level Querying the paragraph outline level Jennifer Murphy Word VBA 1 01-18-2014 01:20 AM
Macro to toggle outline level 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
Macro to toggle outline level 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

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft