Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Range is in Field (Word XP )

    (See also the archaic and convoluted <!post=Range is in Field,39243>Range is in Field<!/post> )

    I don't know if the change is in me, or in XP, but I've run into this problem again - and this time found a solution.

    I have built an array of paragraphs, identifying empty ones, and am now working backwards through the array, deleting null paragraphs. The code bombed with an error "'5904' Cannot Edit Range" when I tried to effect the .Delete.

    I inserted the test for Fields.Count and have now managed to bypass the paragraph.

    It appears that the failure (to delete) occurred at the last paragraph of a rather large Table of Contents. {TOC f}. Once my subscript lng reduced by one, my loop trolled merrily through each paragraph within the {TOC} and kept on going.

    Go figure. Perhaps there was a bug in Word97 that has been fixed in WordXP; perhaps I wasn't thinking straight back in 2001.

    <pre> ''' Loop to delete empty paragraphs
    For lng = UBound(strPR, 2) To LBound(strPR, 2) + 1 Step -1
    Application.StatusBar = lng & " of " & ActiveDocument.Paragraphs.Count
    ' rng.Paragraphs(lng).Range.Select
    If strPR(intcEmpty + LBound(strPR, 1), lng - 1) = "True" Then
    If rng.Paragraphs(lng).Range.Fields.Count > 0 Then ' we don't do field interiors
    Else

    rng.Paragraphs(lng).Range.Delete
    End If
    Else
    rng.Paragraphs(lng).SpaceBefore = strPR(intcSpaceBefore + LBound(strPR, 1), lng - 1)
    rng.Paragraphs(lng).SpaceAfter = strPR(intcSpaceAfter + LBound(strPR, 1), lng - 1)
    End If
    Next lng</pre>


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

    Re: Range is in Field (Word XP )

    The real fun starts if you have nested fields...

    It's been a while since I had to deal with that problem, though.

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

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Range is in Field (Word XP )

    Right!

    Luckily for me, in this particular case, I'm processing everything but fields, so it is sufficient for me to veer away the moment I see a tail twitching in the long grass.

    Dealing with (nested) fields is certainly more cumbersome that not dealing with fields.

Posting Permissions

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