For example I have 100 pages of a Microsoft Word document and I want to extract each page’s contents into one file (page_1.doc for first page, page_2.doc for second page and so on), so how should I do it?
Fortunately I can run a simple macros script to do it. Watch this tutorial:
Here is the script:
Sub MakeEachPageSeparated() ' ' MakeEachPageHTML Macro ' ' ' Used to set criteria for moving through the document by page. Application.Browser.Target = wdBrowsePage For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages") 'Select and copy the text to the clipboard ActiveDocument.Bookmarks("\page").Range.Copy ' Open new document to paste the content of the clipboard into. Documents.Add Selection.Paste ' Removes the break that is copied at the end of the page, if any. Selection.TypeBackspace ChangeFileOpenDirectory "C:\converted" DocNum = DocNum + 1 ActiveDocument.SaveAs FileName:="page_" & DocNum & ".doc", FileFormat:=wdFormatDocument, AddToRecentFiles:=True ActiveDocument.Close ' Move the selection to the next page in the document Application.Browser.Next Next i ActiveDocument.Close savechanges:=wdDoNotSaveChanges End Sub
Or try this one:
Sub NewSeparation() Dim orig As Document Dim page As Document Dim numPages As Integer Dim idx As Integer Dim fn As String ' Keep a reference to the current document. Set orig = ActiveDocument ' Calculate the number of pages numPages = ActiveDocument.BuiltInDocumentProperties("Number of Pages") For idx = 1 To numPages ' Make sure the document is active orig.Activate ' Go to the page with index idx Selection.GoTo What:=wdGoToPage, Name:=idx ' Select the current page Selection.GoTo What:=wdGoToBookmark, Name:="\page" ' Copy the selection Selection.Copy ' Create a new document Set page = Documents.Add ' Activate it page.Activate ' Paste the selection Selection.Paste ' Generate the file name fn = "C:\converted\page_" + CStr(idx) + ".doc" ' Save the document as Word 97-2003 page.SaveAs FileName:=fn, FileFormat:=wdFormatDocument, AddToRecentFiles:=False ' Close the document page.Close Next End Sub