Consulting

Results 1 to 3 of 3

Thread: Replace Form Field Checkbox with Content Control Checkbox

  1. #1

    Replace Form Field Checkbox with Content Control Checkbox

    Word 2016

    I need to replace the legacy form field checkboxes with content control checkboxes.

    I have never written any macros, please excuse my ignorance. We have old checklists that I want to update. I have my feeble attempt at code below. Example document is attached. There may be a better way to fix this.

    Sub ChkBxTab()
    Dim i As Long
    With ActiveDocument
    For i = .FormFields.Count To 1 Step -1
    With .FormFields(i)
    If .Type = wdFieldFormCheckBox Then
    Set Rng = .Range
    .Delete
    Rng = wdContentControlCheckBox
    End If
    End With
    Next
    End With
    End Sub

    Any help is appreciated!
    Attached Files Attached Files

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Your document already contains text formfields, and formfields and content controls should not be used in the same document; doing so can lead to problems - especially when checkboxes are involved. In any event, having Yes/No/NA checkboxes is only asking for problems; you should consider using a single dropdown with Yes/No/NA options for each item, so only one answer per item can be given.

    The following macro will replace your text formfields with plain text content controls and your checkbox sets with dropdown content controls:

    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long, Rng As Range, CCtrl As ContentControl
    With ActiveDocument
      While .FormFields.Count > 0
        Set Rng = .FormFields(.FormFields.Count).Range
        With Rng
          Select Case .FormFields(1).Type
            Case wdFieldFormTextInput
              .Text = vbNullString
              Set CCtrl = .ContentControls.Add(wdContentControlText)
              CCtrl.SetPlaceholderText Text:="Type Here"
            Case wdFieldFormCheckBox
              .MoveStartUntil vbCr, wdBackward
              .Text = vbNullString
              Set CCtrl = .ContentControls.Add(wdContentControlDropdownList)
              CCtrl.SetPlaceholderText Text:="Select one"
              With CCtrl.DropdownListEntries
                .Add "Yes"
                .Add "No"
                .Add "N/A"
              End With
          End Select
        End With
      Wend
    End With
    Application.ScreenUpdating = True
    End Sub
    You can see the processing result in the attached.
    Attached Files Attached Files
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,358
    Location
    My Content Control Tools Add-in has a utility for converting FFs to CCs:

    https://gregmaxey.com/word_tip_pages...rol_tools.html
    Attached Images Attached Images
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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