Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    May 2001
    Thanked 0 Times in 0 Posts

    Stopping a loop at the end of a Word document (Word 2000)

    I feel really dumb; there must be an easy answer to this one. I need to test each line of a file to see if it begins with a number from 0 to2 and delete the lines that begin with any other character (in case you are wondering, this is a geneaology GEDCOM file with some junk in it). I have that part working fine, but at the end I have to press CTRL+Break to stop the program. My old VB knowledge doesn't seem to apply here -- "While not eof(1)" etc.)

    How can I test for the end of the Word document and have the program end gracefully?

    Thank you for your help.

    Judy M

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Stuttgart, Baden-W, Germany
    Thanked 0 Times in 0 Posts

    Re: Stopping a loop at the end of a Word document (Word 2000)

    Hi Judy,

    In Vba, you usually round up all Paragraphs (or other Items), and loop.
    No need to keep looking whether the last one has gone through the door <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    <pre>Dim myPara As Paragraph
    For Each myPara In ActiveDocument.Paragraphs
    Select Case Left$(myPara.Range.text, 1)
    Case "0"
    Case "2"
    Case Else
    End Select
    Next myPara</pre>

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>Klaus

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

    Re: Stopping a loop at the end of a Word document (Word 2000)

    And if you find that the For Each approach "skips" a paragraph after a deletion, the workaround is to write your loop this way:

    Dim intCounter as Integer
    For intCounter = ActiveDocument.Paragraphs.Count To 1 Step -1
    'run test on ActiveDocument.Paragraphs(intCounter).Range.Text
    Next 'intCounter

    Not sure if the paragraphs collection has this problem, but you will know soon enough!

Posting Permissions

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