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.
Method 1: Extract Current Section to a New Document
- First of all, position cursor in a target section.
- Next press “Alt+ F11” to invoke VBA editor in Word.
- Then on the left column, click on “Normal”.
- And on menu bar, click “Insert”.
- Then choose “Module” on that drop-down menu.
- 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
- Next, click “Run” on menu bar or hit “F5”.
- Then there will pop up the “Browse” window. Pick a place to store the new document and click “OK”.
- And in the “File Name” box, enter the name for new file and 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.
- To begin with, open target document.
- Then follow steps in method 1 to install and run a macro.
- 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
- 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
this is incredible. thank you