Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fieldrange select doesnt select (Word 2002 /XP SP3)

    Hello

    I have the following code that checks all the fields in the footer.
    If the fieldcode "mDocID" is found I would like to select the field and apply a Word heading style. However when I use the code
    fldThis.Select
    it doesnt appear to select the field and therefore doesnt apply the style.

    any ideas?

    'Add the footer code if necessary
    Dim rangeFooter As Range
    Set rangeFooter = Selection.HeaderFooter.Range

    'look for the docid field
    Dim fldThis As Field, bDocIDFieldFound As Boolean
    For Each fldThis In rangeFooter.Fields
    If fldThis.Type = wdFieldDocProperty Then
    If InStr(fldThis.Code, "mDocID") Then
    bDocIDFieldFound = True

    fldThis.Select

    '
    ' check if the footer style exists
    '
    If Selection.Style = ActiveDocument.Styles("Footer") Then

    Else
    '
    ' if not apply the footer style format
    '
    Selection.Style = ActiveDocument.Styles("Footer")
    End If

    End If
    End If

    would be greatly appreciated.
    diana

  2. #2
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: fieldrange select doesnt select (Word 2002 /XP SP3)

    I think that the line
    If InStr(fldThis.Code, "mDocID") Then
    should be changed to
    If InStr(fldThis.Code.Text, "mDocID") Then

    Not on my developer PC right now, so cannot test this.

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

    Re: fieldrange select doesnt select (Word 2002 /XP SP3)

    Are you sure the selection is in the appropriate footer when this code is run? If the selection is not in a header or footer, Selection.HeaderFooter.Range will fail.

    Note: it should not be necessary to select the field. You can apply a style to a range directly, instead of first selecting it and applying the style to the selection.

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: fieldrange select doesnt select (Word 2002 /XP SP3)

    Hans

    Yes I have another function that goes thru all the docs footers. and formats the current footer.
    This section footer function then calls the function code I have pasted in this post. Ive edited the code so I wouldnt have to paste alot of code in this post.

    diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

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

    Re: fieldrange select doesnt select (Word 2002 /XP SP3)

    The code works fine for me in Word 2002 SP-3, but if I remember correctly, you're using a document management system. That might make the difference. Your code in itself looks OK.

Posting Permissions

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