Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-29-2017, 03:13 PM
macropod's Avatar
macropod macropod is online now Consolidating data from Word into one Excel Windows 7 64bit Consolidating data from Word into one Excel Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word & Excel 2010 - Best Options To Auto Insert MySQL & Excel Data? Hoser Word 1 03-17-2017 03:47 PM
Consolidating data from Word into one Excel Consolidating various word docs in one Max Downham Word 6 11-23-2015 05:07 PM
Populate Word Drop-down list with Excel column then auto fill form fields with Excel data Faldinio Word VBA 7 10-19-2014 06:03 AM
Consolidating data from Word into one Excel Need help consolidating data from separate sheets tiwas Excel 1 10-07-2014 04:57 AM
Consolidating data from Word into one Excel Consolidating data using Macro mrjamez Excel Programming 2 05-22-2012 06:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft