View Single Post
 
Old 05-20-2014, 04:09 PM
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 Tab character causes style change to Heading 4 after macro

I wrote a little macro to switch between Outline and Normal view and to set the Outline level. I use it to allow me to move heading sections around using the Alt+Shift+Up/Down Arrow keyboard shortcuts.

The problem that I am having is that sometimes (but not always), after using the macro to move a section, the tab key changes the style setting. If the paragraph has the Normal style, the tab key (anywhere in the paragraph) will change it to the Heading 4 style. If it is already a heading style, it changes the level. It's driving me crazy.

If I save the document and reopen it, the tab key behaves normally. If I just do something else in the document, the tab key will eventually stop misbehaving.

The macro works great and has for quite awhile. I have it assigned to the Alt+o keyboard shortcut. To use it, I position go to the heading of the section I want to move and invoke the macro (Alt+o). If I am in Normal view, the macro switches to Outline view and changes the outline level to the heading level of that line. I can then move the entire section. When I am done, I invoke the macro again. Seeing that I am in Outline view, the macro sets the outline level to "All" and switches back to Normal view.

Here's the code:
Code:
Sub MyOutlineLevel()
Dim DocLayout   'The document layout (view)
Dim ParOutline  'The paragraph outline level (1-9 + 10 (=Bodytext))
DocLayout = ActiveWindow.View
ParOutline = Selection.Paragraphs(1).OutlineLevel

Select Case DocLayout                 'Check the layout (view)
  Case wdNormalView, wdPrintView        'If Normal or Page (print) view,
    If ParOutline = 10 Then               'If BodyText paragraph,
      Exit Sub                              'Do nothing
    Else                                  'Else, must be a heading
      ActiveWindow.View.ShowHeading ParOutline  'Show headings only up to that level
    End If
    ActiveWindow.View.Type = wdOutlineView      'And switch to Outline view
  Case wdOutlineView                    'If Outline view,
    ActiveWindow.View.ShowAllHeadings     'Show everything
    ActiveWindow.View.Type = wdNormalView 'And switch back to Normal view
  Case Else                             'For any other view,
    Exit Sub                              'NOP
End Select

End Sub
HELP!!!
Reply With Quote