Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2014, 04:09 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Tab character causes style change to Heading 4 after macro Windows XP Tab character causes style change to Heading 4 after macro Office 2007
Competent Performer
Tab character causes style change to Heading 4 after macro
 
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
  #2  
Old 12-13-2015, 10:28 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Tab character causes style change to Heading 4 after macro Windows XP Tab character causes style change to Heading 4 after macro Office 2007
Competent Performer
Tab character causes style change to Heading 4 after macro
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Hello,

I never got any replies on this question. It's still happening. Can anyone suggest a fix?

Thanks

PS: I have some new data.

If I simply rerun the macro from the line where the tab key is misbehaving, the problem is fixed. I set a breakpoint in the macro and stepped through what it does. If it is not called from a heading line, it just assigns two variables and exits.

Code:
Dim DocLayout   'The document layout (view)
Dim ParOutline  'The paragraph outline level (1-9 + 10 (=Bodytext))

DocLayout = ActiveWindow.View
ParOutline = Selection.Paragraphs(1).OutlineLevel
Why would that change anything?
Reply With Quote
  #3  
Old 12-14-2015, 02:31 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Tab character causes style change to Heading 4 after macro Windows XP Tab character causes style change to Heading 4 after macro Office 2007
Competent Performer
Tab character causes style change to Heading 4 after macro
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default

Well, I narrowed the problem down to just a few lines of code, but I still do not understand what is happening. I created two subs: Test1 & Test2.

Running Test1 changes the behavior of the tab key so that it increases the heading level (not the list level). Note that the variable temp is not used. All that is needed is to reference the Selection.Paragraphs(1).OutlineLevel property.
Code:
  Sub Test1()
  ' This sub sets Outline View then Normal View
  ' It also changes the tab key to increase the heading level
  ' Keyboard shortcut: ACS+O
  
  Dim temp
  ActiveWindow.View.Type = wdOutlineView
  temp = Selection.Paragraphs(1).OutlineLevel
  ActiveWindow.View.Type = wdNormalView
  
  End Sub
Running Test2 restores the normal tab key behavior. In this sub, the property is referenced in an IF statement that does nothing.
Code:
  Sub Test2()
  ' This sub resets the tab key to be a tab key
  ' Keyboard shortcut: ACS+P
  
  If Selection.Paragraphs(1).OutlineLevel = 10 Then Exit Sub
  
End Sub 


Does this behave this way on anyone’s machine other than mine?

Is there a command to restore the tab behavior to be just a tab function?
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tab character causes style change to Heading 4 after macro Macro to change style name with " in it gundas Word VBA 3 04-02-2013 06:20 AM
Change single character in PPT to another font macro rtwwpad PowerPoint 1 01-19-2013 05:08 PM
Tab character causes style change to Heading 4 after macro Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
Change the leading of a character style??? Char t Word 1 11-05-2011 01:18 PM
Character style stripped while applying paragraph style sams_gates Word 0 08-29-2009 02:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:54 PM.


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