Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2016, 06:46 AM
hiwire03 hiwire03 is offline Extract Data from Word Documents Windows 7 32bit Extract Data from Word Documents Office 2013
Novice
Extract Data from Word Documents
 
Join Date: Dec 2014
Posts: 17
hiwire03 is on a distinguished road
Default Extract Data from Word Documents

I am using Office 2013 64 bit.

I have many word documents in the undermentioned format:

1.Heading A
blah blah

2.Heading B
blah blah blah

3.Heading C
blah blah blah

What I am trying to achieve is a document that extracts contents based on the Headings and consolidates then into a separate file. So I would have three files:

File X :
Heading A from File 1
Heading A from File 2
Heading A from File 3


..

File Y :
Heading B from File 1
Heading B from File 2
Heading B from File 3
..

File Z :
Heading C from File 1
Heading C from File 2
Heading C from File 3
..

If the same can be reversed it would we awesome.

Thanks in AdvanceI am using Office 2013 64 bit.

I have many word documents in the undermentioned format:


1.Heading A
blah blah


2.Heading B
blah blah blah


3.Heading C
blah blah blah


What I am trying to achieve is a document that extracts contents based on the Headings and consolidates then into a separate file. So I would have three files:


File X :
Heading A from File 1
Heading A from File 2
Heading A from File 3
..


File Y :
Heading B from File 1
Heading B from File 2
Heading B from File 3
..


File Z :
Heading C from File 1
Heading C from File 2
Heading C from File 3
..


If the same can be reversed it would we awesome.


Thanks in Advance,
Reply With Quote
  #2  
Old 01-28-2016, 03:00 AM
macropod's Avatar
macropod macropod is offline Extract Data from Word Documents Windows 7 64bit Extract Data from Word Documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by hiwire03 View Post
I have many word documents ...
What I am trying to achieve is a document that extracts contents based on the Headings and consolidates then into a separate file. So I would have three files
...
If the same can be reversed it would we awesome.
You mention extracting the data to three files. What if a document has more than three headings, or less than three headings? As for the headings themselves, are they properly formatted using a Heading Style? If so, which one(s)? If not, how is the macro supposed to recognise each heading?

Your reversal request is ambiguous. Data extraction doesn't delete the headings from the source documents, so there should be nothing to reverse.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-28-2016, 03:28 AM
hiwire03 hiwire03 is offline Extract Data from Word Documents Windows 7 32bit Extract Data from Word Documents Office 2013
Novice
Extract Data from Word Documents
 
Join Date: Dec 2014
Posts: 17
hiwire03 is on a distinguished road
Default

The three files are just an example. What I need are a X number documents (each containing just ONE heading (Level 1) alongwith its contents) consolidated from Y number of documents.

Please ignore the reversal part for now.
Reply With Quote
  #4  
Old 01-29-2016, 09:19 PM
macropod's Avatar
macropod macropod is offline Extract Data from Word Documents Windows 7 64bit Extract Data from Word Documents Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 macro:
Code:
Sub CollateDocumentHeadings()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, i As Long, Rng As Range
Dim wdDocSrc As Document, wdDocTmp As Document, wdDocOut As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
Set wdDocTmp = Documents.Add
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  i = 0
  If ThisDocument.FullName <> strFolder & "\" & strFile Then
    Set wdDocSrc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDocSrc
      With .Range
        With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Text = ""
          .Replacement.Text = ""
          .Format = True
          .Style = wdStyleHeading1
          .Execute
        End With
        Do While .Find.Found
          i = i + 1
          Set Rng = .Duplicate
          With Rng
            .End = .End - 1
          End With
          With wdDocTmp
            If .Sections.Count < i Then
              .Range.InsertAfter vbCr
              .Sections.Add Range:=.Characters.Last, Start:=wdSectionNewPage
            End If
            .Sections(i).Range.Characters.Last.InsertBefore Rng.Text & vbTab & strFile & vbCr
          End With
          .Collapse wdCollapseEnd
          .Find.Execute
        Loop
      End With
      .Close SaveChanges:=False
    End With
  End If
  strFile = Dir()
Wend
With wdDocTmp
  .SaveAs2 FileName:=strFolder & "\Headings Master List.docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
  For i = 1 To .Sections.Count
    Set Rng = .Sections(i).Range
    With Rng
      .MoveEnd wdCharacter, -1
    End With
    Set wdDocOut = Documents.Add(Visible:=False)
    With wdDocOut
       .Range.FormattedText = Rng.FormattedText
      .SaveAs FileName:=strFolder & "\Headings (" & i & ") List.docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
      .Close SaveChanges:=True
    End With
  Next
End With
Set wdDocSrc = Nothing: Set wdDocTmp = Nothing: Set wdDocOut = 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
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
data, extract, word 2013

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract the filter data Sandhya Excel Programming 2 10-25-2015 09:02 AM
Extract Data from Word Documents Extract Excel Data from Chart in Word cillianmccolgan Word 1 08-15-2014 01:42 AM
Extract Data from Word Documents How to extract data from Excel database to create word report for each patient (row) nightale Word 3 07-06-2014 04:17 PM
Extract Data from Word Documents How to extract two different output documents from 1 master document? wimvanrompuy Word 3 06-20-2014 06:43 AM
Extract Data from Word Documents How to Extract key data from word iliauk Word 3 11-08-2013 04:37 PM

Other Forums: Access Forums

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


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