Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    May 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search for first period in a paragraph

    I think this is a simple question for those of you in the know.
    I have a numbering scheme where heading 2 is "POINT I" where the number is followed with "nothing. All other heading numbers are followed with a tab.
    Heading 2 is centered and a manual line break is applied for the text
    ............POINT I.
    THE CONTRACT STATES XYZ
    (Leading ...... Is only to demo the center. There are no dot leaders)
    When the tOc is generated, the reference is POINT I. THE CONTRACT STATES XYZ
    Since there is no tab, the hanging indent doesn't align with other TOC items , some wrap, others have 3 digit numbers "POINT III". for this particular TOC, heading 2 and 3 are both set to be at TOC 2 level.
    So, i created a macro for a simple search for TOC2 style period space and replace with ".^t"
    It works well, until Dr. Somebody's name appeared in the level.
    How can i write the macro to only replace the first period it sees in a paragraph?
    I've been using third party numbering tools for so long that i've never bumped in to this.
    If i "follow number with tab" then the point is not centered.
    Any takers?
    Much appreciated!

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts
    I can't work out where the Heading 1 style ends in your described example. Can you post a document that demonstrates the styles and TOC content you are trying to arrive at?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    May 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew. Attached is a sample document. You will see that Heading 1 indent needs to align with levels 2 and 3. If i add a ^t instead of the . space then i get what I need. This is what I use. It does what I need it to do unless there is a period in the text of the heading.
    I only want it to replace the first period/space. (This is for a separate document where the attorney wanted to swap heading 1 and 2 for a particular brief, so it references TOC2,not TOC1)

    Sub TOCUpdate()
    ' TOCUpdate Macro
    ' Replace space after TOC2/heading 2 with a tab character
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("TOC 2")
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("TOC 2")
    With Selection.Find
    .Text = ". "
    .Replacement.Text = ".^t"
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    Attached Files Attached Files

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts
    Rather than needing a macro to do this, I would split the multi-line headings into two paragraphs and include a styleref field to get the paragraph numbering. This avoids the need for a macro.

    See the attached document which positions the styleref field off the side of the page so the user can't see it.
    sample document with article one_v1.docx

    If you don't like this method then we can work on a macro but I believe a non-macro solution will be less problematic in the long run.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,980
    Thanks
    0
    Thanked 208 Times in 189 Posts
    Using Find/Replace on a TOC is a waste of time, as anytime the TOC is updated (as typically occurs at print time), whatever you've modified will be undone.

    In this case, a possible solution is to (a) replace the first the newline characters in each heading with a tab character, (b) set the heading line spacing to double and (c) add the \w switch to the TOC field.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    862
    Thanks
    0
    Thanked 10 Times in 9 Posts
    You could also confine the Find/Replace to Sentences(1) of the paragraph range. That's not always 100% accurate in determining the end of the sentence (based on punctuation), but it's fairly accurate.

  7. #7
    Star Lounger
    Join Date
    May 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew, great idea, but sadly, the documents in questions are 150-300+ page briefs, with many different hands (in several countries) in the document, so it would be too hard to explain StyRef fields. We FINALLY have the attorneys using styles and not direct formatting!
    Paul, i understand the issue with updating the TOC, but the macro is more for the WP staff to quickly generate a TOC, add tabs, and give to paralegals to sort through main points.
    My example was for heading 1, but in fact, the level in question contains blocks of text that follow POINT I, II, III and needs the tab to make it easier to read.
    Richard, i will try that option.
    I appreciate all of your help.
    Sincerely.
    Amy

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,980
    Thanks
    0
    Thanked 208 Times in 189 Posts
    Quote Originally Posted by techtrain View Post
    Paul, i understand the issue with updating the TOC, but the macro is more for the WP staff to quickly generate a TOC, add tabs, and give to paralegals to sort through main points.
    My example was for heading 1, but in fact, the level in question contains blocks of text that follow POINT I, II, III and needs the tab to make it easier to read.
    Hi Amy,

    Regardless of the heading level, the solution I suggested should work and, insofar as it means modifying your headings is concerned, could be implemented via Find/Replace and a simple modification of the Style. From there, all you'd need to do is to add the \w switch to the TOC field. That's far more robust than anything you can achieve by modifying the TOC contents.
    Last edited by macropod; 2013-11-26 at 04:07. Reason: typo
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    Lounger
    Join Date
    Nov 2008
    Location
    Sydney, New South Wales, Australia
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post
    I think TOC1 is what you mean in macro and that works fine - I altered your TOC code and macro and ran for TOC1 not 2 - of course you can only run the basic macro once to put tab in instead of space in TOC 1.
    You should use LinkedParagraphs but not sure what version Word you are using.

    I would modify Heading 1 to Double Spacing as Paul said and put one line break that is silly to invoke a line break twice manually.

    Otherwise what you have works.

    janinecrutch.com
    Attached Files Attached Files

  10. #10
    New Lounger
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I am still in a fix for TOC code..It's not working anymore..Is there any other alternative to resolve it? I have even tried
    Google apps security

  11. #11
    Star Lounger
    Join Date
    May 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Paul & Janine, but I can't change the style to double because the heading descriptions need to be single spaced. If I replace the new line character with a tab then the alignment isn't completely centered. I still have to try Richard's suggestion to find sentence 1 of the paragraph range. My macro works assuming that there is only one period in the heading. I'm just trying to fix it so that once it finds the first period it moves to the next paragraph.
    Thx

    Oh, and Janine, this was just a random sample I grabbed to show the TOC alignment. It is an old document and the style is a paragraph style, not linked. I am using 2010.
    Last edited by techtrain; 2013-12-01 at 09:56.

  12. #12
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,549
    Thanks
    3
    Thanked 149 Times in 142 Posts
    Since you still haven't given up on this and I can't be bothered writing code to find just the first instance in a paragraph perhaps this will do the job. This is a wildcard search and finds an instance of an uppercase roman numeral followed by period space and replaces the space with a tab. You could add the style restriction as well if you wanted.
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "([IVX]). "
    .Replacement.Text = "\1.^t"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Find.Execute Replace:=wdReplaceAll
    End With
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  13. #13
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    3,980
    Thanks
    0
    Thanked 208 Times in 189 Posts
    Quote Originally Posted by techtrain View Post
    I can't change the style to double because the heading descriptions need to be single spaced. If I replace the new line character with a tab then the alignment isn't completely centered.
    In that case, you could still insert the tab on the empty line between the Article # and the Heading text. Again, this can be done via a simple Find/Replace. What I was trying to avoid was having two space characters (one either side of the tab) when the \w switch is used. With a tab on the empty line between the Article # and the Heading text, you can still have a properly-performing TOC, but with a single space character at the start of the Heading text.

    Whilst it's all very well to go adding tabs to the TOC directly, IMHO that's just asking for trouble further down the line.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  14. #14
    Star Lounger
    Join Date
    May 2003
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Paul. I respect YHO! This is a major producer who has 100-300 page briefs. The secy sends them to a support center to generate a table! IMHO, i think it shouldn't matter if the text isn't aligned while reviewing the TOC, but, we aim to please. So, for now, my little macro to easily re-generate a "clean" table will suffice. I'm already down the line of further trouble....wait for my nex post!
    Best,
    Amy

  15. #15
    Lounger
    Join Date
    Nov 2008
    Location
    Sydney, New South Wales, Australia
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hi Techtrain

    You could have the support center lock the TOCs to remind them to run the macro - better still attach the lock at end of macro.

    lock the TOC with Ctrl+F11 (you can then unlock with Ctrl+Shift+F11). Just a thought.

    Regards
    janinecrutch.com

Posting Permissions

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