I have a seemingly trivial VBA task. However, I do not normally use VBA and almost never in the context of Microsoft Word. I have a Word form that utilizes Content Control fields (as well as a few ActiveX radio buttons) and need to test it by printing a time stamp and completed form entries to a comma delimited file. When I run the following code:
Sub WriteToText()
Dim DataFile As String
Dim StrData As String
Dim CCtrl As ContentControl
Dim bControl_Exists As Boolean
DataFile = "C:\Users\Annabanana\Documents\Data.txt"
StrData = "": Open DataFile For Append As #1
StrData = Format(Now, "DD-MMM-YYYY hh:mm:ss")
With Application.ActiveDocument
bControl_Exists = .Saved
For Each CCtrl In ThisDocument.ContentControls
With CCtrl
Select Case .Type
Case Is = wdContentControlCheckBox
StrData = StrData & "," & .Checked
Case wdContentControlDate, wdContentControlDropdownList, wdContentControlComboBox, wdContentControlText
StrData = StrData & "," & .Range.Text
Case Else
End Select
End With
Next
End With
Print #1, StrData: Close #1
End Sub
I get the datestamp but nothing else. Ideally I would like to eventually print field tags and their corresponding values as such:
Tag1 Value1 Tag2 Value2 Tag3 Value3 .............
Eventually all of those would print to a database, but at this point I just want to be able to see how the data comes out of the form and how I need to transform it prior to loading. Any advice is greatly appreciated. Thank you.