Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-24-2015, 04:49 PM
macropod's Avatar
macropod macropod is offline Extracting Data from Word Documents Windows 7 64bit Extracting Data from Word Documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

For some macros that show how you might go about this for a single document, see:
https://www.msofficeforums.com/word-...acters-up.html
https://www.msofficeforums.com/word/...doc-excel.html
For code demonstrating how to process an entire folder and export Word data to Excel, see:
https://www.msofficeforums.com/word-...html#post64259

If your data are held in formfields or content controls, the following Excel macro might be more useful. It extracts data from all formfields & content controls in all Word documents in the selected folder and populates the first available row in the active Excel worksheet with the data for each document.
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 FmFld As Word.FormField, CCtrl As Word.ContentControl
Dim strFolder As String, strFile As String
Dim WkSht As Worksheet, c As Long, r 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 = 0
    For Each FmFld In .FormFields
      c = c + 1
      With FmFld
        Select Case .Type
          Case Is = wdFieldFormCheckBox
            WkSht.Cells(r, c) = .CheckBox.Value
          Case Else
            WkSht.Cells(r, c) = .Result
        End Select
      End With
    Next
    For Each CCtrl In .ContentControls
      c = c + 1
      With CCtrl
        Select Case .Type
          Case Is = wdContentControlCheckBox
            WkSht.Cells(r, c) = .Checked
          Case wdContentControlDate, wdContentControlDropdownList, wdContentControlRichText, wdContentControlText
            WkSht.Cells(r, c) = .Range.Text
          Case Else
        End Select
      End With
    Next
    .Close SaveChanges:=False
  End With
  strFile = Dir()
Wend
wdApp.Quit
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
If you want to record the document's name as part of the data, change:
c = 0
to:
c = 1: WkSht.Cells(r, c) = strFile
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Data from Word Documents Extracting data, pivot tables, and maybe VBA help? rbexcelhelp Excel Programming 3 05-09-2015 12:13 AM
Extracting Data from Word Documents extracting data from word docs stubevh Word 2 03-04-2015 06:27 PM
Extracting Data from Word Documents formula writing for extracting data jennamae Excel 1 11-15-2013 08:40 PM
Extracting Data from Word Documents Extracting data from excel Eric855 Word 6 07-25-2013 08:02 AM
Extracting Contacts Data from Excel Caesar Outlook 1 05-08-2011 05:54 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:06 PM.


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