Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Feb 2003
    Location
    Texas, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loop Macro in Word (2002)

    I want to create a macro for a document that only has addresses that does a "Keep lines together" for all addresses in document so I want a macro that loops as many times as necessary until it's done. I have a series of commands (1. turn select mode on, 2. find Paragraph Marker, Paragraph Marker, 3. turn on Para keep lines together, 4. search again and continue the loop as many times as necessary to go through entire document). I can't seem to figure out the looping in Word (I have it for Word Perfect but not Word). Any help would be greatly appreciated!!

  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: Loop Macro in Word (2002)

    Hi Mary:
    I'm not a VBA expert so I can't give you a macro, BUT...

    Since the entire document is addresses, why don't you just select everything (Ctrl+A) & right click any line & choose Paragraph. Then go to line & page breaks tab & choose Keep lines together. That will apply that formatting to the entire document.

    Better yet, when you're done doing that, click inside the style box, type a new style name & press <enter>. Choose update style. That style will now have the formatting that you want (keep lines together). You can use that style for addresses whenever you want. You can add the style to the normal or a custom template for future use.
    Cheers,

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Loop Macro in Word (2002)

    Do the addresses have "new line" characters separating the parts of the address or "paragraph breaks"? In the first case, Keep lines together probably does what you want, but in the second case, Keep with next may be needed. Keep with next should not be applied to any blank paragraphs between addresses, so your macro could simply count the number of words in a paragraph and if it is more than one word, set the Keep with next formatting, like so:

    Sub KeepNonBlankWithNext()
    Dim para As Paragraph
    For Each para In ActiveDocument.Paragraphs
    If para.Range.Words.Count > 1 Then
    ' The paragraph marker counts as 1 word!
    para.KeepWithNext = True
    End If
    Next
    End Sub

    Hope this helps.

  4. #4
    New Lounger
    Join Date
    Feb 2003
    Location
    Texas, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop Macro in Word (2002)

    jscher2000 - This is BRILLIANT!!! There are paragraph breaks between the addresses. This works wonderfully!!! <img src=/S/bananas.gif border=0 alt=bananas width=33 height=35> You read my mind !!! I misstated yesterday (I guess I've been staring at it too long <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15> ) - I did need the "Keep with next" and not the "Keep lines together." Thank you oh so very much <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15> !!!

    Phil, thanks also for your response - I'll keep your idea in mind for future reference!

  5. #5
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Loop Macro in Word (2002)

    Hi Mary,

    If each of these address is comprised of a signle para, and all paras are all formatted using the same Word Style, you could achieve the same result by selecting any one of them and using Format|Style|Modify|Format|Paragraph|Line and Page breaks, then checking the 'Keep lines together' check box. No macros required!!

    To change them from multiple paras to signle paras, do a Search/Replace with Find = ^p and Replace = ^l. Then if you originally had two para markers between each address, do a Search/Replace with Find = ^l^l and Replace = ^p or ^p^p

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  6. #6
    New Lounger
    Join Date
    Feb 2003
    Location
    Texas, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Loop Macro in Word (2002)

    Thank you for your input ! I didn't even think about styles but yes that would be the easiest thing to do!! Unfortunately, I was helping our Word Processing department who work for any one of 250 people and, unfortunately, the majority of the users don't knowingly (or intentionally) use styles <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15> .

Posting Permissions

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