2 Fast Ways to Extract Sections from Your Word Document

In this article, we will offer you 2 fast and easy ways to extract sections from your Word document to another one or several.

It happens quite often to extract contents from one document to another. And in our previous article, we have discussed how to extract pages from document. For detailed information, you can refer to this article: 2 Quick Ways to Extract Individual Pages from Your Word Document

Today, we will show you how to extract by section.    Extract Sections from Your Word Document

Method 1: Extract Current Section to a New Document

  1. First of all, position cursor in a target section.
  2. Next press “Alt+ F11” to invoke VBA editor in Word.
  3. Then on the left column, click on “Normal”.
  4. And on menu bar, click “Insert”.
  5. Then choose “Module” on that drop-down menu.Click "Normal"->Click "Insert"->Click "Module"
  6. Double click to open the new module and paste following codes there:
Sub SaveCurrentSectionAsNewDoc()
  Dim strFolder As String
  Dim dlgFile As FileDialog
  Dim strNewFileName As String
  Dim objDocAdded As Document
  Dim objDoc As Document
 
  ' Initialization
  Set objDoc = ActiveDocument
 
  ' Pick a place to store the new file.
  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
 
  With dlgFile
    If .Show = -1 Then
      strFolder = .SelectedItems(1) & "\"
    Else
      MsgBox "Select a folder first!"
      Exit Sub
    End If
  End With
 
  strNewFileName = InputBox("Enter new file name here: ", "File Name")
 
  ' Select and copy current section range.
  objDoc.Bookmarks("\Section").Range.Select
  Selection.Copy
 
  ' Open a new document to paste the above selection.
  Set objDocAdded = Documents.Add
  Selection.Paste
 
  ' Save and close the new document.
  objDocAdded.SaveAs FileName:=strFolder & strNewFileName & ".docx"
  objDocAdded.Close
End Sub
  1. Next, click “Run” on menu bar or hit “F5”.Paste Codes->Click "Run"
  2. Then there will pop up the “Browse” window. Pick a place to store the new document and click “OK”.Choose a Storing Path->Click "OK"
  3. And in the “File Name” box, enter the name for new file and click “OK”.Enter File Name->Click "OK"

Now you have extracted the section to a new document.

Method 2: Extract Each Section in Document to Individual New Ones

This way can help you batch process all sections in a document. Of course, we will need a macro, too.

  1. To begin with, open target document.
  2. Then follow steps in method 1 to install and run a macro.
  3. Only this time replace that macro with this one:
Sub SaveEachSectionAsADoc()
  Dim objDocAdded As Document
  Dim objDoc As Document
  Dim nSectionNum As Integer
  Dim strFolder As String

  Dim dlgFile As FileDialog
 
  ' Initialization
  Set objDoc = ActiveDocument
 
  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)
 
  ' Pick a location to keep new files.
  With dlgFile
    If .Show = -1 Then
      strFolder = .SelectedItems(1) & "\"
    Else
      MsgBox "Select a folder first!"
      Exit Sub
    End If
  End With
 
  ' Step through each section in current document, copy and paste each to a new one.
  For nSectionNum = 1 To ActiveDocument.Sections.Count
    Selection.GoTo What:=wdGoToSection, Which:=wdGoToNext, Name:=nSectionNum
    ActiveDocument.Sections(nSectionNum).Range.Copy
 
    Set objDocAdded = Documents.Add
    Selection.Paste
 
    ' Save and close new documents.
    objDocAdded.SaveAs FileName:=strFolder & "Section " & nSectionNum & ".docx"
    objDocAdded.Close
  Next nSectionNum
End Sub
  1. Still, in the “Browse” window, choose a storage path and click “OK”.

Fix Irritating Word Errors

It’s common to come across some Word errors while using it. Annoying it might be, we must take time to recover word as soon as possible. Because the longer we delay it, the severer the data loss can be. Therefore, it’s suggested to get hold of a repairing utility in advance.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted xls and pdf repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *