none
Word Lists: Need to automatically decrease indentation below selected node RRS feed

  • Question

  • Hello all,

    I'm stuck on a problem that I think needs to be handled via code (please correct me if I'm wrong).

    I have a custom multilist like so:

    1. Line1
    2. Line2
                a. Line3
                b. Line4
                            i. Line4

    When I decrease indentation on one line, everything below that level needs to decrease indentation by 1.  So using the example above, I'm going to decrease indentation on "b." and this is what I'm striving to achieve:

    1. Line1
    2. Line2
                a. Line3
    3.
    Line4
                a. Line4

    Currently word will do this (which is what I don't want):

    1. Line1
    2. Line2
                a. Line3
    3.
    Line4
                            i. Line4

    If it can be done through defining my multilist then great, otherwise if I need to tackle this with code (C# is my preference but I can also program in VB) please help me with:

    1.  How do I "listen" for the decrease event.
    2.  How would I loop through the multilist, inspect, and decrease every level that is below that level?

    Please help, I'm in a sink or swim situation!

    Thank you in advance,

    Nick Metnik

     

    • Edited by Nicklaus Metnik Friday, April 8, 2011 4:52 PM The post looked good int the editor, but then the editor stripped my formatting of the lists making it impossible to describe the problem.
    Friday, April 8, 2011 4:49 PM

Answers

  • Ok, here is the answer in code (thank you Ajay B., you make it look so easy!):

     public static void PromoteList(Word.Application app)
        {
          Range rngCurrent = app.Selection.Range;
          int iSelectedListLevel;
          int iNextListLevel;
    
          //Store the current list level
          iSelectedListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Decrease Indent
          rngCurrent.ListFormat.ListOutdent();
    
          //Move to the next paragraph / list item
          rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
          iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Perform decrease indent for all list items with list level greater than the selected one (i.e., all child items)
          while (iNextListLevel > iSelectedListLevel)
          {
            rngCurrent.ListFormat.ListOutdent();
            rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
            iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
          }
        }
    
        public static void DemoteList(Word.Application app)
        {
          Range rngCurrent = app.Selection.Range;
          int iSelectedListLevel;
          int iNextListLevel;
    
          //Store the current list level
          iSelectedListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Increase Indent
          rngCurrent.ListFormat.ListIndent();
    
          //Move to the next paragraph / list item
          rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
          iNextListLevel = rngCurrent.ListFormat.ListLevelNumber ;
    
          //Perform increase indent for all list items with list level greater than the selected one (i.e., all child items)
          while (iNextListLevel > iSelectedListLevel)
          {
            rngCurrent.ListFormat.ListIndent();
            rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
            iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
          }
        }
    

    Thanks again Rich and Cindy!

    Nick

    Friday, April 15, 2011 10:09 PM

All replies

  • Hi NetNick

     

    It can be built in code but it doesn’t have to be.

     

    1)      Start with the Styles dialog and select that you want to create a new style.

    2)      Give the Style a unique name.

    3)      In the Style Type box select List and a Create New Style from Formatting appears

    4)      You can fix this stuff up later so go immediately to the Format button

    5)      Choose Numbering and a Modify Multi Level Appears

    6)      The important things you need to do here are to define the Level and Link them to a numbered list level.

    7)      Start and Level 1, it’s the box on the left and highlight one.

    8)      Then from the pull down list on the right labeled Link level to style choose List Number and you’ll see  a notation made in the middle text box

    9)      Now select 2 from the level list and link it to the style named List Number 2

    10)  Repeat until you’ve linked all of the levels you will use to a List Number # style.

    11)  Ok out and you’re done.

     

    Hope this helps


    Regards
    Friday, April 8, 2011 6:00 PM
  • Hello RichMichaels,

    My list looks correct, but the "child" levels are not decreasing indentation.  They renumber but they stay put.
    I followed your post and seems to still behave that way.

    Thank you for your help,

    Nick 

    Friday, April 8, 2011 9:55 PM
  • I did miss documenting something that is on the Multilevel list dialog; you have to select the More button to see the Link to Style list box.

    However, I retested the steps that I did document and it works on my machine.  Maybe I'm confused about how you want the list Promote and Demote to behave.

    If I have a list as below, and want to Promote 1.c to a level 1 …

    1)      Lkjaslkjas

    a)      Lkjljlkjlk

    b)     Llkjasdlkjsa

    c)      Lasjdlkasjd

    d)     Kljljlkj

    By only promoting 1.c it ends up looking like this

    1)      Lkjaslkjas

    a)      Lkjljlkjlk

    b)     Llkjasdlkjsa

    2)      Lasjdlkasjd

    a)      Kljljlkj

    Admittedly, if I want b, c, and d from the first list to look like this

    1)      Lkjaslkjas

    a)      Lkjljlkjlk

    i)       Llkjasdlkjsa

    ii)     Lasjdlkasjd

    iii)  Kljljlkj

    Then I have to select all three and click demote.

     

    BTW, I use the terms Promote and Demote versus how Word describes them as Decrease Indent and Increase Indent just because I think about them as an organizing principle and not an editing mechanic.


    Regards
    Saturday, April 9, 2011 12:44 AM
  • Hello RichMichaels,

    Thanks again for you time and help.

    Just to clarify more in case I'm not describing the problem well enough.
    Using the multiline dialog and advanced section, I have defined my list perfectly.  Everything behaves and numbers as expected.  Perhaps what I'm looking for isn't possible via built in functionality.  My list works just like you are showing above where "d" becomes "a" after you promote "1.c".
     
    Anyways, using your example with a slight modification:

    If I promote 1.c, I want promoting to happen beneath it as well.
    So I need this:

     

    1)       Lkjaslkjas

    a)       Lkjljlkjlk

    b)      Llkjasdlkjsa

     c)       Lasjdlkasjd

    i)      Kljljlkj

     

    To become this:

    1)       Lkjaslkjas

    a)       Lkjljlkjlk

    b)      Llkjasdlkjsa

           2)       Lasjdlkasjd

    a)      Kljljlkj


    See how "i)" automatically promoted after you promoted 1.c?
    Does that make sense and is it achievable? 

    Thanks again for your patience and help,

     

    Nick


     

    Saturday, April 9, 2011 1:03 AM
  • Crap, the indentation got messed up after posting.  Anyways, I think you get the idea:  The list starts out as 3 levels and end up as 2 levels after promotion and cascading.
    Saturday, April 9, 2011 1:06 AM
  • Hi Nick,

    It's just Rich BTW. Why it's run together ... I don't know. :-)

    Anyway, I "Think" I understand.  My former post that shows the indenting was done directly in a Word document in which I had made the list settings. All of the indents and how I tried to describe what I did, came directly from me writing the post in Word, making the list indents by using the increase and decrease indent buttons, and then all I did was copy and paste it into this forum.

    So when I took this ...

    1)      Lkjaslkjas

    a)      Lkjljlkjlk

    b)     Llkjasdlkjsa

    c)      Lasjdlkasjd

    d)     Kljljlkj

    I placed my cursor on c and select what I call promote and Word calls decrease indent, the level 2 child "c" item became a level 1 parent item and the former level 2 child item "d" to parent 1 became a level 2 child item "a" to parent 2.  Boy, I can't believe I'm describing it this way. :-)

    Now if on the other hand if you wanted to "increase the indent" on item "c" (I call that demoting in the outline list), that item should become an "i" and the item below it will not demote unless it was also selected prior to clicking the "increase indent button".  If you want everything below the individual line you have indented to likewise indent and change its numbering then to my knowledge custom coding will be required.  However, I'm not sure that can even be done to full satisfaction because how will it know when to stop demoting subsequent lines of text ... that pleases everyone?

    So I conclude that either we have "a common language that continues to separate us" :-) or there is something in your list implementaton that's preventing it from functioning properly, or I'm still not understanding the objective. The later, which at this hour and my recently concluded "very confusing" meeting with a Regatta Yacht Race Committee, leads me to question my understanding of anything and everything. :-)

    When you tried this in a new document did you happen to save and reopen the document after making the style list?

     


    Regards
    Saturday, April 9, 2011 2:40 AM
  • Hi Nick

    FWIW I support what Rich is saying and Word should work as he describes, assuming

    1. The document is not damaged
    2. Nothing is interfering with Word's normal functionality
    3. This is Word for Windows 97 or later (which version is it, BTW)?

    One thing I haven't picked up from the discussion (but may have missed): how are you asking Word to increase/decrease? The best place to check the basic functionality is the outline view, using the buttons that Ribbon/toolbar provide. It should/will work in other views with keyboard shortcuts, but sometimes the shortcuts don't work correctly. Best to test in Outline view where we can be sure Word's internal functionality is doing what it's supposed to...

    That all of this works depends very much on the numbering being a single, multi-level list and not two "lists" that look like they belong together, but are actually separate entities. Word is notorious for so-called "spaghetti numbering" and what you're seeing makes me suspect this is what's happening. It might be best to test "starting from scratch".

    And I can also highly recommend the steps and information for creating and controlling numbering on Shauna Kelley's site: http://www.shaunakelly.com/word/numbering/outlinenumbering.html

     


    Cindy Meister, VSTO/Word MVP
    Saturday, April 9, 2011 7:39 AM
    Moderator
  • Hello RichMichaels and Cindy Meister,

    Thank you both.  It does help if I post the version ;)
    I'm using and supporting Word 2007 and newer for this project.  RichMichaels, I empathize with you on your Yacth Committee.  This project is for the US government, that's really all I can say, but yeah our government can have some pretty far out demands

    I'll take a look at that link and give this another go with another fresh document.  I'll post my results.

     

    Thanks again for such rapid response,

    Nick

    Sunday, April 10, 2011 10:49 PM
  • Hi Nick,

     

    Thinking about your issue, I had this additional thought.

     

    After making your List Number modifications if you’re not seeing the List Number styles behaving as I have described then where are they being saved; to the document or to a template?

     

    If they are being saved to a template then all other open documents with that template attached must be closed.  If you are modifying styles in the Normal template it’s really best to close all other open documents, modify your styles, mark the check box “New documents based on this template”, save the document, close the document, and exit Word completely. When you reopen the document, or others, your modified styles should all be in place.

     

    Hope this helps

     


    Regards
    Monday, April 11, 2011 2:35 PM
  • Thank you RichMichaels,

    It's an excellent point, nice "gotcha" to look out for.
    I'm going to burn one of our support calls right now, I just can't get it to work :(

    I'll post my results.

    Thanks again and have a great day,

    Nick 

    Monday, April 11, 2011 4:26 PM
  • Hi Nick,

    Save your support call, they'll probably have you try this.

    Close all Office applications.

    From Windows Explore or however you view your file system structure, navigate to your Normal template. If XP it's in your Documents and Settings\your name\Application Data\Microsoft\Templates folder. If Vista or Win 7 it's in Users\your name\App Data\Roaming\Microsoft\Templates

    Rename it to oldNormal.dotm

    Open Word and set the List Number Style up.

    Then see if it works. If it does, we've isolated the problem down to a conflicting list style setting in your former Normal template. If it doesn't you can revert back to your former normal template and spend that support call.

     


    Regards
    Monday, April 11, 2011 4:46 PM
  • Hello Rich,

    I have 40hrs to blow on tech support so I'm waiting for my call back :)

    I tried what you described and I must be missing something.

    Do you have a document sample where you can get the list to behave as described.
    I'm going to demonstrate again just to make sure we are on the same page just in case I'm not getting it:

    1.     1.          Level 1

    a.       Level 2

                                                                   i.      Level 3

    I Need to promote all child items (fyi the reorder/numbering works fine).

    1.     1.          Level 1

    2.    2.           Level 2

    a.       Level 3

    I've prepared a document to email. If you are interested in seeing it, my email is nick@umetech.net

    Thanks again Rich,

    Nick

    Monday, April 11, 2011 8:42 PM
  • Ahh geez, I'm having a hell of a time posting my examples, my doc will be easier to follow :)
    Monday, April 11, 2011 8:43 PM
  • Hi Nick,

    I've sent back a document with the List Number styles working as they should. I believe the problem was that you might have started trying to first create them by modifying the default list paragraph style.

    The way to do it, is to create the new unique style name that is linked to the List Number style. In essense you're modifying your unique style name and not the default list style.

    Hope this helps


    Regards
    Monday, April 11, 2011 11:17 PM
  • Just FYI here is my response from Microsoft:

    "Thank you Nick for your response. I do need to do some research to figure out the possibility of such a behavior out-of-the-box, though possibility seems less. I will update you by tomorrow on this."

    @Rich - Thanks again for your continued help.  If support gives me an answer I'll be certain to notify you immediately.

    Monday, April 11, 2011 11:30 PM
  • Hi Nick,

    Okay, tell MS support that the problem is in level 3 and beyond.

    If the list has just 2 levels everything I have tested appears to be fine. The problem occurs when a 3rd level is introduced. At that point it's not dealing with it consistently/correctly.

    To verify this they will also need to save the file, close and reopen and that's when the issue seems appear ... I believe. I've tried this so many times, and I thought I checked all these levels when I initially created the list but now, once again, I'm questioning everything.

    The bottom-line is this ... Nick you are correct, this is not working consistently and I finally somehow see it but I can't figure out the pattern to its failure.

    Maybe somebody else can.

    Wish I could have helped you more.

     


    Regards
    Tuesday, April 12, 2011 2:24 AM
  • Hello Rich,

    Thank you, you've actually been a huge help.  I now have a lot more going into my call.
    Thanks again for your persistent and professional efforts.

    Sincerely,

    Nick

    Tuesday, April 12, 2011 3:41 AM
  • Official word from Microsoft (in short, must be tackled by code):

    "Unfortunately, the feature of automatically promoting all children list items doesn’t exist in Word – users have to first select all the items and then apply promote, as I described in the previous email. However, I have sent this question to the Microsoft Support group to understand if there is any other workaround or custom code. I will update you by tomorrow as soon as I hear back from them."

    Tuesday, April 12, 2011 11:42 PM
  • Hi Nick

    <<I'm stuck on a problem that I think needs to be handled via code (please correct me if I'm wrong).>>

    Thanks for sending me the sample document. That's refreshed my memory and I think you're right about needing to handle this via code. Now that I sit here and work with it (and set up my own document) I believe Word has "always" worked this way. I just revved up a VM with 2003 on it (where numbering is the same all the way back to 97, more or less) and it's the same.

    What you want to do works IF you use a numbering style linked to the heading styles AND you do the promotion/demotion in the Outline view. I tested in 2003, 2007 and 2010 and they all work the same way.

    But any other outline style numbering, any other styles, and you need to use code to change the numbering level.

    You might want to double-check this, though, with the folks on "Answers" who work with Numbering on a more regular basis http://answers.microsoft.com/en-us/office/forum/word. But I tried creating my own set of styles and setting an outline Level for each. Then linking the styles to a numbering level - no joy.


    Cindy Meister, VSTO/Word MVP
    Friday, April 15, 2011 3:39 PM
    Moderator
  • Hello Cindy,

    Thanks again for your help as well.
    Currently I'm working with the Office-dev team at Microsoft.  They are brewing a batch of code for me now and I'm just waiting for a sample.

    My biggest struggle lately is finding some good examples of interopting with Word's lists.  I haven't done a ton of Word programming so it's been a challenge.  
    I'm going to post the results when I have them in hand.

    Thanks again,

    Nick

    Friday, April 15, 2011 3:48 PM
  • Ok, here is the answer in code (thank you Ajay B., you make it look so easy!):

     public static void PromoteList(Word.Application app)
        {
          Range rngCurrent = app.Selection.Range;
          int iSelectedListLevel;
          int iNextListLevel;
    
          //Store the current list level
          iSelectedListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Decrease Indent
          rngCurrent.ListFormat.ListOutdent();
    
          //Move to the next paragraph / list item
          rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
          iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Perform decrease indent for all list items with list level greater than the selected one (i.e., all child items)
          while (iNextListLevel > iSelectedListLevel)
          {
            rngCurrent.ListFormat.ListOutdent();
            rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
            iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
          }
        }
    
        public static void DemoteList(Word.Application app)
        {
          Range rngCurrent = app.Selection.Range;
          int iSelectedListLevel;
          int iNextListLevel;
    
          //Store the current list level
          iSelectedListLevel = rngCurrent.ListFormat.ListLevelNumber;
    
          //Increase Indent
          rngCurrent.ListFormat.ListIndent();
    
          //Move to the next paragraph / list item
          rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
          iNextListLevel = rngCurrent.ListFormat.ListLevelNumber ;
    
          //Perform increase indent for all list items with list level greater than the selected one (i.e., all child items)
          while (iNextListLevel > iSelectedListLevel)
          {
            rngCurrent.ListFormat.ListIndent();
            rngCurrent = rngCurrent.Next(WdUnits.wdParagraph);
            iNextListLevel = rngCurrent.ListFormat.ListLevelNumber;
          }
        }
    

    Thanks again Rich and Cindy!

    Nick

    Friday, April 15, 2011 10:09 PM