Consulting

Results 1 to 4 of 4

Thread: Change Check Box character to text

  1. #1
    VBAX Newbie
    Joined
    May 2018
    Posts
    4
    Location

    Question Change Check Box character to text

    Hi

    I have a word 2016 form with content controls, some of which are checkboxes.

    Using a macro I got from this forum (from Macropod), I'm extracting the form data into Excel but the checkboxes are coming in as symbols.

    I recorded a macro for Find / Replace but it changed every cell !

    I want the ☒ (selected checkbox) to change to be Yes and the ☐ (unselected checkbox) to be No, with a macro and not find/replace each time.

    Thanks
    Stef
    Last edited by StefM; 05-01-2018 at 11:42 PM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Show us the Code you got from Macropod. Simply Copy it in your VBA Editor, then in Our Post Editor, click the menu # icon, then press Ctrl+V
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    May 2018
    Posts
    4
    Location
    Sub GetFormData()
    
      Application.ScreenUpdating = False
    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    Dim CCtrl As Word.ContentControl
    Dim strFolder As String, strFile As String
    Dim WkSht As Worksheet, i As Long, j As Long
    
       strFolder = "c:\users\myname\desktop\answers"
       If strFolder = "" Then Exit Sub
    
       Set WkSht = ActiveSheet
       i = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row
       strFile = Dir(strFolder & "\RESOURCES QUESTIONNAIRE.docx", vbNormal)
    
       While strFile <> ""
         i = i + 1
         Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, _
           AddToRecentFiles:=False, Visible:=False)
         With wdDoc
           j = 0
           For Each CCtrl In .ContentControls
             j = j + 1
             WkSht.Cells(i, j) = CCtrl.Range.Text
           Next
         End With
    
         wdDoc.Close SaveChanges:=False
         strFile = Dir()
       Wend
    
    wdApp.Quit
    Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
    Application.ScreenUpdating = True
    End Sub
    Last edited by SamT; 05-03-2018 at 07:55 AM.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Your code
         With wdDoc
           j = 0
           For Each CCtrl In .ContentControls
             j = j + 1
             WkSht.Cells(i, j) = CCtrl.Range.Text
           Next
         End With
    I don't speak VBA for Word, So you will have to research the ControlType Name

    You need something like
         With wdDoc
           j = 0
           For Each CCtrl In .ContentControls
             j = j + 1
             If ControlType(CCtrl) = "???" Then
               If CCtrl = [True|0|Checked|Yes] Then '??? I dunno
                 WkSht.Cells(i, j) = "Yes"
               Else: WkSht.Cells(i, j) = "No"
               End If
             Else: WkSht.Cells(i, j) = CCtrl.Range.Text
             End If
           Next
         End With
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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