none
How do I get an unformatted Field.Code.Text? RRS feed

All replies

  • Hi David,

    What kind of fields are you talking about and what is it exactly you need to archieve?

    Monday, April 11, 2011 1:05 AM
  • Hi;

    Sorry, the AutoTextList control - it has a /t "tooltip text" and I need the text from Field.Code.Text in mixed case from it so I can get the \t "text" part as written (I have XPath selects in it).

    thanks - dave


    Very funny video - What's your Metaphor?
    Monday, April 11, 2011 2:04 AM
  • Hi Dave,

    I tried to reproduce, but I always get the exact same fieldcode, mixed as I entered it.

    Could you give an example of an exact fieldcode and the result you're getting?

    Monday, April 11, 2011 10:19 AM
  • Hi;

    Please download http://www.windwardreports.com/temp/FieldCode.zip. Inside it is docx file. On page 2 is a field that is displayed as <STATE>. Calling FIeld.Code.Text on that field returns an all upper case string.

    I get the field from Range.Fields.

    ??? - thanks - dave


    Very funny video - What's your Metaphor?
    Monday, April 11, 2011 3:18 PM
  • Hi Dave,

    It turns out that the fields are directly formatted with AllCaps.

    There may be other ways, but you can try something like:

    Dim oField As Field
    
     For Each oField In ActiveDocument.Content.Fields
      'Check if field is formatted as AllCaps
      If oField.Code.Font.AllCaps Then
       'reset
       oField.Code.Font.AllCaps = False
       Debug.Print oField.Code.Text
       'set formatting again
       oField.Code.Font.AllCaps = True
      Else
       Debug.Print oField.Code.Text
      End If
     Next
     
     Set oField = Nothing

    Hope this helps,
    kind regards,

    Astrid

    Monday, April 11, 2011 4:27 PM
  • Hi;

    Thank you - that is what we're presently doing. However, it causes the cursor to flicker and sets the document as dirty(edited) so it's not a good solution.

    Hopefully one of the MS people know of a clean way to get the underlying string.

    thanks - dave


    Very funny video - What's your Metaphor?
    Monday, April 11, 2011 4:47 PM
  • You can pick up the saved property of the document and put it back to it's orginal value afterwards.

    As for the flickering, there's application.screenupdating.

    Otherwise, I think the solution should be searched in either formatting the underlying data or using a switch to format the field result instead of formatting the text of the field.

    Monday, April 11, 2011 6:40 PM
  • Hi David,

    Here's a slightly different approach. No flickering and the document state remains unchanged:

    Sub Test()
    Dim oField As Field
    For Each oField In ActiveDocument.Content.Duplicate.Fields
      'Check if field is formatted as AllCaps
      With oField.Code
        If .Font.AllCaps Then
          'reset
          .Font.AllCaps = False
          Debug.Print .Text
          'set formatting again
          ActiveDocument.Undo 1
        Else
          Debug.Print .Text
        End If
      End With
    Next
    Set oField = Nothing
    End Sub


    Cheers
    Paul Edstein
    [MS MVP - Word]
    Monday, April 11, 2011 8:53 PM