"That property is not available on this object" for Word field object property "result" when type is "wdFieldTOCEntry"

KSteele 66 Reputation points
2022-09-02T14:09:16.477+00:00

Hello,

This following code works fine:

    Dim FFrange As Range  
    For Each FF In ActiveDocument.Fields  
        If FF.Type = wdFieldRef Then  
            Set FFrange = FF.Result  
            'FFrange.HighlightColorIndex = wdRed  
        End If  
    Next  

This following code generates "That propery is not available on this object"

    Dim FFrange As Range  
    For Each FF In ActiveDocument.Fields  
        If FF.Type = wdFieldTOCEntry Then  
            Set FFrange = FF.Result  
            'FFrange.HighlightColorIndex = wdPink  
        End If  
    Next  
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. KSteele 66 Reputation points
    2022-09-02T14:39:19.613+00:00

    I was able to fix it by using the "Code" property instead of "result" to get the range. I guess it's because wdFieldToCEntry does not have a "result" like REF field does, since there's no place to input text. But I would think it would just return an empty value since technically all fields must have this property?

    https://learn.microsoft.com/en-us/office/vba/api/word.field

    0 comments No comments