View Single Post
 
Old 06-21-2018, 05:56 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following macro (Macro1) will help you tag content controls in selected text, but surely you would want to tag the controls before you send out the files, in order to be able to get a meaningful result?

The extraction add-in was suggested on the basis that you wanted to extract all the data from your form. It extracts to an Excel worksheet from which you can process the data.

Alternatively you can use a macro to read ony the data required (see macro2)

Code:
Sub Macro1()
    TagControls "Q1Ans"
End Sub

Sub Macro2()
ReadControls "Q1Ans"
End Sub

Sub TagControls(strTag As String, Optional iStart As Integer = 0)
'Graham Mayor - http://www.gmayor.com - Last updated - 21 Jun 2018
Dim oCC As ContentControl
Dim i As Integer
    For i = 1 To Selection.Range.ContentControls.Count
        Set oCC = Selection.Range.ContentControls(i)
        oCC.Tag = strTag & CStr(i + iStart)
        oCC.Title = strTag & CStr(i + iStart)
        DoEvents
    Next i
lbl_Exit:
    Set oCC = Nothing
    Exit Sub
End Sub

Sub ReadControls(strTag As String)
Dim oCC As ContentControl
Dim oSource As Document
Dim oDoc As Document
    Set oSource = ActiveDocument
    Set oDoc = Documents.Add
    For Each oCC In oSource.ContentControls
        If oCC.Tag Like strTag & "*" Then
            If oCC.ShowingPlaceholderText = False Then
                oDoc.Range.InsertAfter oCC.Range.Text & vbCr
            End If
        End If
        DoEvents
    Next oCC
lbl_Exit:
    Set oCC = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote