Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Finding a group of paragraphs with the same style

    I am using Word 97. I would like to create a macro that would find any group of paragraphs with the same style. Such as a group of paragraphs with a style named "Step". I have such a style that I use for lists. Obviously, not every list has the same number of steps (and therefore paragraphs). However, every list does have different styles before and after it.

    After finding this block of text, I have another macro I already created that I will run on what is selected during the find.

    Then I want to search for the next block again and again until I get to the end of the document.

    Thanks for any help you can give!!
    Troy

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Finding a group of paragraphs with the same style

    Hi Troy,

    The easiest way would be to do something similar to what was done in the bullets and numbering macro, where you do a For Each loop through every paragraph in the document and test for style - if the style name matches, then do something to the paragraph.

    This would be simplest, and whether this would work depends on just what your other macro is going to do the paragraph or paragraphs - can you provide some more detail on what is the other macro's purpose and how you have set it up (posting the code wouldn't hurt <g>)?

    Looping through a document to find groups of paragraphs can certainly be done, but it is a bit more of a project and would take a little more planning to create - as above, knowing the nature of the other macro it's got to link up to would help before starting out.

    Gary

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a group of paragraphs with the same style

    Sorry I keep leaving out important information. The macro I created was to restart numbering. As I'm sure you know, numbering continues by default from list to list and must be restarted each time. While it is certainly possible to run this macro for each list (which is what we do currently), it would nice, especially in cases where we are not creating from scratch, to search for these blocks (which could be anywhere from 2 to 20 paragraphs each), select them, and restart the numbering all at once. I've included my current (lengthy though it may be due to the style containing multi-level numbering) macro below:

    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(1)
    .NumberFormat = "%1."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 18
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdBlack
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = "Step"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(2)
    .NumberFormat = "%2."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 18
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 30
    .TabPosition = 36
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(3)
    .NumberFormat = "%3)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 30
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 42
    .TabPosition = 48
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(4)
    .NumberFormat = "%4)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 57
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 71.4
    .TabPosition = 75
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(5)
    .NumberFormat = "(%5)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 71.4
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 89.4
    .TabPosition = 89.4
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(6)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(7)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(8)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(9)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).Name = ""
    Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
    wdOutlineNumberGallery).ListTemplates(2), ContinuePreviousList:=False, _
    ApplyTo:=wdListApplyToWholeList
    End Sub


    If you can improve on this macro feel free, but my main desire is to be able to search for and select a block of text which will already have the same style, so I can run this (or some other) macro to restart the numbering.

    Thanks again!!
    Troy

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Finding a group of paragraphs with the same style

    Hi Troy,

    Well, I was afraid it would be something like that!<g>

    Still clinging to the idea of an easy fix, here are a couple of thoughts:

    1. Make the 'Step' style Level 2 in the outline numbering list.
    - this one wouldn't require a macro. Since a Level 2 style in an outline numbering list can be set to automatically restart after each occurrence of a Level 1 style, one way to approach this would be to have your Step style occupy Level 2 in the outline list.

    This would require you having a paragraph with the Level 1 style applied to it, before each occurence of the Step paragraphs. The Level 1 style does not have to have any numbering attributes applied to it; it just needs to occupy Level 1 in the outline numbering list.

    The Level 1 paragraph that precedes every Step list could simply be some sort of decorative element, or alternatively could be an empty paragraph set to a point size of 1 with no space above or below. You can make "keep with next" paragraph part of its formatting, as well as assigning the 'Step' style as the "style for following paragraph".

    2. If the above isn't workable and a macro is necessary, it still might be possible to keep it simple:

    When you need to restart numbering for a group of outline numbered paragraphs, you don't really need to select them all, you only need to be in the first one. A macro to find all contiguous blocks of like-styled paras (in order to select/restart them) is doable, but not easy. By contrast, a macro that needs to find only those 'Step' paras that are not preceded by another 'Step' para, would be much easier. I'll try to post back with something along those lines, if I can.

    Gary

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Finding a group of paragraphs with the same style

    Here's a macro along the lines of idea #2, that should work for you.
    (I would have liked to have worked out a way to do this with the Range object rather than Selection, and with a function rather than a sub, but it is getting late and I had to go with what worked! <img src=/S/yawn.gif border=0 alt=yawn width=15 height=15>)

    <pre>Public Sub FindFirstStepParas()
    'Gary Frieder April 2001
    'Find each instance of a paragraph with 'Step' style,
    ' that is not preceded by a paragraph with 'Step' style
    Dim objDocParas As Paragraphs
    Dim lngParaCt As Long
    Dim n As Long
    Set objDocParas = ActiveDocument.Paragraphs
    lngParaCt = objDocParas.Count
    For n = 2 To lngParaCt
    If objDocParas(n).Style = "Step" Then 'test prev para's style
    If objDocParas(n - 1).Style <> "Step" Then
    objDocParas(n).Range.Select
    RestartFirstStepPara
    Selection.Collapse
    End If
    End If
    Next n
    End Sub
    '==========================
    Public Sub RestartFirstStepPara()
    With Selection
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(1)
    .NumberFormat = "%1."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 18
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdBlack
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = "Step"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(2)
    .NumberFormat = "%2."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 18
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 30
    .TabPosition = 36
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(3)
    .NumberFormat = "%3)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 30
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 42
    .TabPosition = 48
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(4)
    .NumberFormat = "%4)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 57
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 71.4
    .TabPosition = 75
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(5)
    .NumberFormat = "(%5)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 71.4
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 89.4
    .TabPosition = 89.4
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(6)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(7)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(8)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).ListLevels(9)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Tms Rmn"
    End With
    .LinkedStyle = ""
    End With
    ListGalleries(wdOutlineNumberGallery).ListTemplate s(2).Name = ""
    Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
    wdOutlineNumberGallery).ListTemplates(2), ContinuePreviousList:=False, _
    ApplyTo:=wdListApplyToWholeList
    End With

    End Sub
    </pre>


  6. #6
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Finding a group of paragraphs with the same style

    I really appreciate your efforts in helping me restart number. The macro you sent worked great, except it ran unbareably slow. So I tried your first suggetion (about making my "Step" style start at level 2. After I read this suggestion, I had a "DUHH" moment as I grasped the intelligence and simplicity of this solution. <img src=/S/doh.gif border=0 alt=doh width=15 height=15>

    I have been able to implement this with one small exception: The only way to set up this style in a way that it does not revert was to do it in a macro. If I try set it manually in the Styles dialog box, by the time I hit my last OK, my "Step" style is tied once again to level 1.

    As I said, I was successful at implementing this via a macro, but if I ever have to go into the bullets and numbering dialog (say to continue numbering in the rare cases where my level 1 style precedes the step style in the MIDDLE of a list) I find that it reverts, but can still "customize" the numbering to start at # (where # is the number at which my list should continue). This is not a major problem in this instance, but I would love to be able to get around it so I can use this same method in other, more widely used, templates.

    I have printed my macro text below (you will notice that "Step" is actually linked to level 3 because I knew that in some cases I would have several lists in a row without a "Normal" style paragraph in between, so I put another style at level 2 as another means for restarting it):

    Sub UDRestartNumbering()
    '
    ' UDRestartNumbering Macro
    ' Macro created 04/19/01 by Troy Wells
    '
    With ActiveDocument.Styles("Step")
    .AutomaticallyUpdate = False
    .BaseStyle = ""
    .NextParagraphStyle = "Step"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(1)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingNone
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = wdUndefined
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdBlack
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = "Normal"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(2)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingNone
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = wdUndefined
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = "Procedure Head"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(3)
    .NumberFormat = "%3."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 18
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = "Step"
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(4)
    .NumberFormat = "%4."
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 18
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 30
    .TabPosition = 36
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(5)
    .NumberFormat = "%5)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 30
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 42
    .TabPosition = 48
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(6)
    .NumberFormat = "%6)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleLowercaseLetter
    .NumberPosition = 42
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 56.4
    .TabPosition = 60
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(7)
    .NumberFormat = "(%7)"
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleArabic
    .NumberPosition = 56.4
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 74.4
    .TabPosition = 74.4
    .ResetOnHigher = True
    .StartAt = 1
    With .Font
    .Bold = False
    .Italic = False
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = 11
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(8)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    With ListGalleries(wdOutlineNumberGallery).ListTemplate s(7).ListLevels(9)
    .NumberFormat = ""
    .TrailingCharacter = wdTrailingTab
    .NumberStyle = wdListNumberStyleNone
    .NumberPosition = 0
    .Alignment = wdListLevelAlignLeft
    .TextPosition = 0
    .TabPosition = 18
    .ResetOnHigher = True
    .StartAt = 0
    With .Font
    .Bold = wdUndefined
    .Italic = wdUndefined
    .StrikeThrough = wdUndefined
    .Subscript = wdUndefined
    .Superscript = wdUndefined
    .Shadow = wdUndefined
    .Outline = wdUndefined
    .Emboss = wdUndefined
    .Engrave = wdUndefined
    .AllCaps = wdUndefined
    .Hidden = wdUndefined
    .Underline = wdUndefined
    .ColorIndex = wdUndefined
    .Size = wdUndefined
    .Animation = wdUndefined
    .DoubleStrikeThrough = wdUndefined
    .Name = "Times New Roman"
    End With
    .LinkedStyle = ""
    End With
    ActiveDocument.Styles("Step").LinkToListTemplate ListTemplate:= _
    ListGalleries(wdOutlineNumberGallery).ListTemplate s(7), ListLevelNumber:= _
    3
    Selection.Style = ActiveDocument.Styles("Step")
    End Sub

    If you can help with this reversion problem, great (I wouldn't be surprised if it were just a MS bug <img src=/S/dragon.gif border=0 alt=dragon width=17 height=15>), but you have already been a great help!!

    Thanks again!!
    Troy

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Finding a group of paragraphs with the same style

    Troy,

    I'll try to give this new wrinkle some thought - in the meantime, there's something you can try that would make the macro I posted run much faster, which would be to put an:

    Application.ScreenUpdating = False

    statement at the beginning of the main procedure and an:

    Application.ScreenUpdating = True

    statement at the end.

    All those Paragraph.Select's take up a lot of time and processing.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •