Results 1 to 5 of 5
  1. #1
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post
    I need to create text files with a hardcoded number every five lines (to help students find their way as they discuss long poems such as Paradise Lost and the Faerie Queene). I realize that I can use Word's line numbering feature to insert a line number every five lines. But I don't know a way to turn those into hard numbers that would stay in a text file conversion.

    I also know how to use SEQ fields for numbering, and that I could turn those fields into their results so I have hard line numbers.

    What I can't figure out how to do is have SEQ fields inserted every five lines, with an increment of five.

    I realize that I could probably write a macro to insert a hard number every five lines. But is there a way to do it with the SEQ fields?

    Thanks,

    Jessica

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could use nested fields like this - remember that you should never type the field braces { } yourself, use Ctrl+F9 to insert them.

    { IF { =Mod({ SEQ Num },5) } = 0 "{ SEQ Num \c }" "" }

    When you insert the field and copy it, it won't display the correct value (chances are you won't see it at all of you're not displaying field codes).
    Select the entire document (Ctrl+A) and update fields (F9), or print preview the document to see the updated values.

  3. #3
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thank you; I'll try this out for the next long poem I work on.

    I ended up doing an amateurish macro which applies the line numbers in the format required to the selection. Have to select each chapter separately, and assume that no chapter has more than 999 lines. The assumption is correct.

    I couldn't find a numeric format that displayed a space if there was no digit, rather than a 0 or nothing. Is there one that I didn't find? If so, I could dispense with the ugly left padding case statement and padstring thing.

    Sub addLineNumbers()
    Dim oPrg As Paragraph
    Dim padstring As String
    Dim prgNum As Long ' the paragraph number
    Dim numSpaces As Long ' the number of spaces leading, if there are any
    padstring = " " ' single digit line numbers need two spaces left padding

    For Each oPrg In Selection.Range.Paragraphs
    prgNum = prgNum + 1
    numSpaces = 0
    Select Case prgNum
    Case 10 ' two-digit line numbers need one space left padding
    padstring = " "
    Case 100
    padstring = ""
    End Select

    If prgNum Mod 5 = 0 Then
    If oPrg.Range.Characters(1) = " " Then
    numSpaces = numSpaces + 1
    While oPrg.Range.Characters(numSpaces + 1) = " "
    numSpaces = numSpaces + 1
    Wend
    oPrg.Range.InsertBefore padstring & prgNum & String(numSpaces, " ")
    Else
    oPrg.Range.InsertBefore padstring & prgNum & String(3, " ")
    End If
    Else
    oPrg.Range.InsertBefore " "
    End If

    Next

    End Sub

    - Jessica

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could use Right(Space(2) & prgNum, 3) to get a string of length 3.

  5. #5
    Lounger
    Join Date
    Apr 2005
    Location
    Silver Spring, Maryland, USA
    Posts
    36
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks. I knew there had to be something better than my brute force slogging available, but not where to look.

    As you can guess, I don't program much these days and learned years ago in a language that was highly procedural and didn't do much smart string processing.

Posting Permissions

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