Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    May 2001
    Location
    Wellington
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Styles (2k/XP/03)

    Is there any way I can make the "Following Paragraph" setting in a style apply to the existing text in a document?

    Normally, if you set a style, you can require that when you create the next paragraph that it use either the same, or some other style.

    I want to go through a document and replace the styles on the basis of the content of the paragraph (easy), but then I want all the subsequent paragraphs (which don't contain the key) to be set to the same style, unless I tell it something else.

    Hope that makes sense. Any ideas?

    Thanks

    Jim

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles (2k/XP/03)

    Hi Jim:
    You can't do this through the style dialog box, at least in Word 2000. However, you might be able to use Find/Replace, depending upon how you will identify the paragraphs to be changed.

    e.g. if you had a question & answer that started with the words "Question" & "Answer", respectively, you could search for paragraphs starting with those words & ending with a paragraph mark. You would then replace the former with itself (^& in the replace box), but using the Format/Style/Question style (from the Find/Replace dialog box). You could do something similar with the answer paragraphs.

    However, without knowing more about the structure of these paragraphs, I can't tell if that approach would work.

  3. #3
    Lounger
    Join Date
    May 2001
    Location
    Wellington
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles (2k/XP/03)

    What you say is correct Phil, and thanks a lot, but doesn't help me. Perhaps I could explain better...

    Imagine a list like this:

    Question: question line one
    random 1
    random 2
    Answer: answer line one
    random 3
    Question: question line one

    I can easily set the style of the 'question' and 'answer' lines, based on content, but I want 'random 1' and 'random 2' (and any more lines before the answer) to also be set to the question style. I want 'random 3' to be the answer style.

    I hope that makes more sense.

    Many thanks for the assistance.

    Jim

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Styles (2k/XP/03)

    Replace the style names and the text you are looking for and this macro should do what you want.

    StuartR
    <code>
    Public Sub SetStyles()

    Dim paraNext As Paragraph
    Dim styQuestion As Style
    Dim styAnswer As Style
    Dim styCurrent As Style

    Set styQuestion = ActiveDocument.Styles("Question")
    Set styAnswer = ActiveDocument.Styles("Answer")
    Set styCurrent = ActiveDocument.Styles("Normal")

    For Each paraNext In ActiveDocument.Paragraphs
    If paraNext.Range.Words(1).Text = "Question " Then
    Set styCurrent = styQuestion
    ElseIf paraNext.Range.Words(1).Text = "Answer " Then
    Set styCurrent = styAnswer
    End If
    paraNext.Style = styCurrent
    Next paraNext

    Set styQuestion = Nothing
    Set styAnswer = Nothing
    Set styCurrent = Nothing

    End Sub
    </code>

  5. #5
    Lounger
    Join Date
    May 2001
    Location
    Wellington
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Styles (2k/XP/03)

    Ah, yeah, I thought that might be required. I was trying to avoid that, but you've done it so elegantly!

    I can't test that from here, but will later today. Many thanks.

    Cheers

    Jim

Posting Permissions

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