Results 1 to 14 of 14
  1. #1
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    finding lines with fewer characters (xp sr2)

    We're just setting up a book for the press, and we need to check that we do not have lines with spacing that is too wide (we distrust Word's automatic hyphenation, and want to control it ourselves).

    Is there a routine that will enable us to find a line which has less than, say 50 characters?

    many thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding lines with fewer characters (xp sr2)

    But wouldn't it be quite normal for the last line in a paragraph to have less than 50 characters?

    Here is a macro you could run on a copy of the document. It will highlight all lines with less than 50 characters (including punctuation)

    Sub TestShort()
    Const conLength = 50
    Dim rng As Range
    Dim rngPrev As Range
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    Set rng = ActiveDocument.Bookmarks("line").Range
    Do
    If rng.Characters.Count > 1 And rng.Characters.Count < conLength Then
    rng.HighlightColorIndex = wdYellow
    End If
    Set rngPrev = rng
    Selection.MoveDown Unit:=wdLine
    Set rng = ActiveDocument.Bookmarks("line").Range
    Loop Until rngPrev = rng
    Application.ScreenUpdating = True
    Set rng = Nothing
    Set rngPrev = Nothing
    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding lines with fewer characters (xp sr2)

    Dear Hans

    many thanks. But three further things:
    1. The line
    Set rng = ActiveDocument.Bookmarks("line").Range
    is provoking a 5941 error, and I'm told 'the requested member of the collection does not exist'

    2. When I just shut the de###### down, I find that the job has been done, but only for the first page.

    3. If getting it to highlight is difficult, I could cope with its just finding the lines and moving the cursor there (though in that case I'd be glad if we could--as you say--avoid final lines of paragraphs).

    many thanks

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding lines with fewer characters (xp sr2)

    The code worked ok for me in the multi-page documents I tried it on. Try single-stepping through the code to find out where it fails.

  5. #5
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding lines with fewer characters (xp sr2)

    Thanks for this.

    a) is there a simple technique for single stepping, short of putting an apostrophe before each line and then gradually removing the apostrophes?
    [img]/forums/images/smilies/cool.gif[/img] I am now having the experience that the macro works for some documents but not for others. I think the reason is that if it comes across a footnote, it gets cross. It works fine on the book if I delete all the footnotes--and actually that will do for our purposes. (but if there were a simple way of a) avoiding the need to delete the footnotes [img]/forums/images/smilies/cool.gif[/img] excluding the last line (perhaps lines ending in a paragraph mark), it would of course be wonderful..

    best

    Philip

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding lines with fewer characters (xp sr2)

    a) Click anywhere in the procedure and press F8. Each F8 will execute one step. You can inspect the value of variables by hovering the mouse over them.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: finding lines with fewer characters (xp sr2)

    [img]/forums/images/smilies/cool.gif[/img] Too difficult. Sorry.

  8. #8
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding lines with fewer characters (xp sr2)

    many thanks indeed

    P

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

    Re: finding lines with fewer characters (xp sr2)

    To skip the last line of each paragraph, replace the line
    <code>
    If rng.Characters.Count > 1 And rng.Characters.Count < conLength Then
    </code>
    with
    <code>
    If rng.Characters.Count > 1 And rng.Characters.Count < conLength And _
    rng.Characters(rng.Characters.Count) <> vbCr Then
    </code>

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

    Re: finding lines with fewer characters (xp sr2)

    To skip over footnotes, add the following code
    <code>
    Do While Selection.Information(wdInFootnote)
    Selection.MoveDown Unit:=wdLine
    Loop
    </code>

    After the existing line
    <code>
    Selection.MoveDown Unit:=wdLine
    </code>

    StuartR

    Edited by StuartR to add
    This code will go into an infinite loop if the final line in the document is a footnote, but I guess you can check for that easily enough.

  11. #11
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts

    Re: finding lines with fewer characters (xp sr2)

    Have you tried selecting "do full justification like Word Perfect 6.x for Windows" from the tools/options/compatability tab? Because Word Perfect, like many layout programs, both reduces and expands word spacing, the result is more typographical. Word normally only expands word spaces when doing full justification. Try this out on a copy because your doc may be completely repaginated, particularly if you have widow and orphan control on.

    Pam
    Pam Caswell

  12. #12
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding lines with fewer characters (xp sr2)

    Thanks to everyone for these suggestions. I think we're there!

    Pam--how does yours work if I've already got a document created? Do I just change the option, and assume it will happen?

    best wishes

  13. #13
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts

    Re: finding lines with fewer characters (xp sr2)

    Yes, you can change the full justification choice at any time (or change it back). In 2003 it will only apply to the document you selected it in, but it will stick with that document unless you change it.

    Pam
    Pam Caswell

  14. #14
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: finding lines with fewer characters (xp sr2)

    Just in case anyone is interested, here is an updated version of Hans's original macro, with the two suggestions from Stuart.
    I've put in some not very subtle refinements:
    a) to enable you to specify the maximum number of characters in any line to be marked up
    [img]/forums/images/smilies/cool.gif[/img] to avoid the problem with it going into an infinite loop if there is a footnote on the last page.

    Sub TestShort()
    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdPageBreak
    Selection.InsertBreak Type:=wdPageBreak
    Selection.TypeText Text:="aaa"
    Dim CharacterNumber, Prompt1
    Prompt1 = "Below what number of characters do linee need to be marked up?"
    CharacterNumber = InputBox$(Prompt1)


    Dim rng As Range
    Dim rngPrev As Range
    Application.ScreenUpdating = False
    Selection.HomeKey Unit:=wdStory
    Set rng = ActiveDocument.Bookmarks("line").Range
    Do
    If rng.Characters.Count > 1 And rng.Characters.Count < CharacterNumber And rng.Characters(rng.Characters.Count) <> vbCr Then
    rng.HighlightColorIndex = wdYellow
    End If
    Set rngPrev = rng
    Selection.MoveDown Unit:=wdLine
    Do While Selection.Information(wdInFootnote)
    Selection.MoveDown Unit:=wdLine
    Loop
    Set rng = ActiveDocument.Bookmarks("line").Range
    Loop Until rngPrev = rng
    Application.ScreenUpdating = True
    Set rng = Nothing
    Set rngPrev = Nothing
    Selection.EndKey Unit:=wdStory
    Selection.TypeBackspace
    Selection.TypeBackspace
    Selection.TypeBackspace
    Selection.TypeBackspace
    Selection.TypeBackspace

    End Sub

Posting Permissions

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