Suppress unwanted jumping/scrolling on Word 2013 VBA Script

后端 未结 2 843
再見小時候
再見小時候 2020-12-12 01:21

When accessing Legacy Form Field values in my Word 2013 document like this (getting or setting):

\' get
myField = ActiveDocument.FormFields(\"myField\").Resu         


        
2条回答
  •  无人及你
    2020-12-12 01:54

    This is a fantastic workaround if all you need to access is the Result field. Unfortunately, some of the form field properties are not accessible indirectly through the Bookmark collection, most notably StatusText. I am using formfields to build tests that are graded automatically in VBA code, and StatusText is the only field (to my knowledge) that allows you to store static (non-volatile) answer data in each form field.

    Here's a sample of the code I am using. The following loop tests the Result fields to see if they match the answers stored in the StatusText field

    For Each fld In oFormFields
    
        strResult = fld.Result
        strStatus = fld.StatusText
    
        If strStatus = strResult Then
            ' color answer green to show that it was correct
            fld.Range.Font.ColorIndex = wdBrightGreen
         Else
            ' color answer red to show that it was wrong
            fld.Range.Font.ColorIndex = wdRed
         End If
     Next fld 
    

    I see no way of replacing the form field references with bookmark references, but perhaps I am missing something.

提交回复
热议问题