Cells(i, 5).Value = myDoc.SelectContentControlsByTag("checkbox2").Item(1).Checked Cells(i, 4).Value = myDoc.SelectContentControlsByTag("checkbox1").Item(1).Checked Cells(i, 3).Value = myDoc.SelectContentControlsByTag("gender").Item(1).Range.Text Cells(i, 2).Value = myDoc.SelectContentControlsByTag("age").Item(1).Range.Text Cells(i, 1).Value = myDoc.SelectContentControlsByTag("name").Item(1).Range.Text Set myDoc = (Filename:=myFolder & "\" & strFile, ReadOnly:=True, AddToRecentFiles:=False, Visible:=False) Value = Array("name", "age", "gender", "checkbox1", "checkbox2", "singlechoice1", "singlechoice2") Set wdApp = CreateObject("Word.Application") MsgBox myFolder & vbCrLf & "Not Found", vbInformation, "Cancelled - getWordFormData"
#YOUTUBE IMPORT DATA FROM EXCEL TO EXCEL MACRO CODE#
MyDoc.SelectContentControlsByTag("name").Item(1).Range.Text Refactored Code Sub getWordFormData() It is better to refer to the ContentControls by their tag names.
You can refer to an ActiveX control on a Word document by it's name Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = NothingĪll the data (text fields, checkbox) are transferred successfully but, the radio button (which is ActiveX) is not transferred.
Set myDoc = (Filename:=myFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False) StrFile = Dir(myFolder & "\*.docx", vbNormal) MyFolder = "C:\Users\alarfajal\Desktop\myform" I use the following vba code: Sub getWordFormData()ĭim myFolder As String, strFile As Stringĭim myWkSht As Worksheet, i As Long, j As Long I want to automatically transfer hundred word forms to an excel file. I have a form in ms word with some of the fields are content control and some (which are the radio buttons) are ActiveX control.