none
Getting actual text from all caps-styled text RRS feed

  • Question

  • I'm working on a VBA sub that compares the results of DocVariable fields to the value of the variable (to make sure the text of the field wasn't typed over during document authoring). The problem I've run into is that some of the fields have a paragraph style that includes the All Caps font attribute. For some maddening reason, the value of objField.Result (when objField is a DocVariable field that has had all caps applied) is all caps text. This means that the value of the variable (which might be sentence or title case) doesn't match.

    Obviously Word keeps track of the actual text that was provided to the field, because if the all caps designation is removed the case is correct (for instance, title case is retained). But is there any way to access that correct text from within VBA, without actually changing the content of the document?

    The two approaches I've considered (pseudocode):

    Dim bAllCaps as boolean
    
    bAllCaps = objFld.result.font.allcaps
    objFld.result.font.allcaps = false
    
    If objFld.result.text = [function that gets value of related variable] then
       ' do something
    end if
    
    objFld.result.font.allcaps = bAllCaps

    If nothing else comes up, I'll do this, but I'd like to avoid making changes to the document which may be tracked if the user has track changes on.

    Second option is to compare the result and the variable value as lowercase strings, but this wouldn't allow me to catch legitimate changes to the case.

    I'm hoping there is a better third option that lets me access the unformatted text for comparison purposes.

    Thanks!

    Tuesday, October 22, 2013 5:12 PM

All replies

  • Why not just compare the upper case (or lower case) values e.g.

    IF UCase(objFld.result.text) = UCase(value from the function) then

    'do stuff

    End If



    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, October 23, 2013 11:08 AM
  • That was my second option; but then I would miss actual changes of the case. Perhaps that's unavoidable, but I was hoping for access to the actual, unformatted text.
    Wednesday, October 23, 2013 2:19 PM