Results 1 to 6 of 6

Thread: [RESOLVED] Word 2003 Update field issue

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    106

    Resolved [RESOLVED] Word 2003 Update field issue

    Hi all,

    I've had a few users complain about opening docs with cross ref/table of content links. When we recieve docs with them, the below code checks them and goes nuts and tries to repaginate and gets stuck in a loop, till the doc crashes. The code below updates fields except 'formtextinput and 'dropdown' as the update code refreshes/blanks them, which is a nightmare for forms that are submitted to us from other staff.

    Is there a way to omit table of content / cross references but still update fieldcodes such as file path fields inputted into a footer?

    Code:
    Sub UpdateDocumentFooter()
                                ''SECOND ATTEMPT CODE
        Dim iCount As Integer, DocProtect As Boolean
    
        '~~> If protected, unprotect document
        If ActiveDocument.ProtectionType <> wdNoProtection Then
            ActiveDocument.Unprotect
            DocProtect = True
        End If
    
        '~~> Prevent Screen Flickering
        Application.ScreenUpdating = False
    
        '~~> move selection to end of document
        Selection.EndKey wdStory
    
        ActiveDocument.Sections(ActiveDocument.Sections.Count) _
        .Footers(1).Range.Fields.Update
    
        Application.ScreenUpdating = True
    
        '~~> If document was originally protected, then re-protect
        If DocProtect = True Then
            ActiveDocument.Protect Password:="", NoReset:=True, _
            Type:=wdAllowOnlyFormFields
        End If
    End Sub
    
    
    Sub UpdateDocFields()
      
    Dim iCount As Integer
    Dim aField As Field
    Dim DocProtect As Boolean
    
    'On Error GoTo ErrHandler
    
    ' If protected; unprotect document
    If ActiveDocument.ProtectionType <> wdNoProtection Then
       DocProtect = True
       ActiveDocument.Unprotect
    End If
    
    ' Loop through all text form fields in the document.
    For Each aField In ActiveDocument.Fields
    
        'If the form field is a text form OR drop down field...
        If aField.Type = wdFieldFormTextInput Or aField.Type = wdFieldFormDropDown Then
            'do nothing with FormText field
            'MsgBox "Field not updated!" 'TEST MESSAGE ONLY - REMOVE FROM LIVE
        Else
            aField.Update
            'MsgBox "Field updated!" 'TEST MESSAGE ONLY - REMOVE FROM LIVE
       End If
    
    ' Increment icount
    iCount = iCount + 1
    
    
     Next aField
    
    'if document was originally protected, then re-protect
    If DocProtect = True Then
        ActiveDocument.Protect Password:="", NoReset:=True, Type:=wdAllowOnlyFormFields
    End If
    
    'ErrHandler:
    End Sub
    *Edit
    Forgot to mention the ToC's that cause the issue are from docs of quite some size, 15 pages or more.
    Last edited by Kubull; Jun 2nd, 2010 at 10:43 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width