View Single Post
 
Old 09-29-2017, 03:13 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,387
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following Excel macro, which you add to the workbook the data are to be imported into.
Code:
Sub GetFormData()
'Note: this code requires a reference to the Word object model.
'See under the VBE's Tools|References.
Application.ScreenUpdating = False
Dim wdApp As New Word.Application, wdDoc As Word.Document
Dim wdRng As Word.Range, wdFmFld As Word.FormField
Dim strFolder As String, strFile As String, strTxt As String
Dim WkSht As Worksheet, r As Long, c As Long
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set WkSht = ActiveSheet
r = WkSht.Cells(WkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  r = r + 1
  Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc
    c = 1
    With .Tables(1)
      Set wdRng = .Cell(1, 3).Range
      With wdRng
        .End = .End - 1
        strTxt = Replace(.Text, vbCr, "¶")
        WkSht.Cells(r, c) = strTxt
      End With
      For Each wdFmFld In .Range.FormFields
        With wdFmFld
          Select Case .Type
            Case Is = wdFieldFormCheckBox
            Case Else: c = c + 1: WkSht.Cells(r, c) = Replace(wdFmFld.Result, vbCr, "¶")
          End Select
        End With
      Next
    End With
    c = c + 1: WkSht.Cells(r, c) = Replace(.FormFields("Text15").Result, vbCr, "¶")
    With .Tables(2)
      For Each wdFmFld In .Range.FormFields
        c = c + 1
        WkSht.Cells(r, c) = Replace(wdFmFld.Result, vbCr, "¶")
      Next
    End With
    With .Tables(5)
      For Each wdFmFld In .Range.FormFields
        c = c + 1
        WkSht.Cells(r, c) = Replace(wdFmFld.Result, vbCr, "¶")
      Next
    End With
    .Close SaveChanges:=False
  End With
  strFile = Dir()
Wend
wdApp.Quit
WkSht.UsedRange.Replace "¶", Chr(10)
Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
End Function
It includes a folder browser, so all you need do is select the folder with all the forms that are to be processed.

For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm. Although these instructions are for Word, the principles are the same for Excel.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote