How to Export Parts of Document using Word VBA
Copy Content with Formatting to New Document using Word VBA
Not all the tens and hundreds of pages in a Word document interests you or matters to you. There are some documents, which we use for reference. All we need is a paragraph/section from the document. If it is a book we used to take a photo-copy of the same and keep it in a folder. How to do the same in a Word document - and in an automated way with all the formatting intact?
ExportFragment method in Word VBA provides the solution. It creates a new document from the existing one for the Range of your choice.
Here is an example where it exports eleventh paragraph of the document to a new one.
Sub PartofText()
Dim oWDRange As Word.Range
Set oWDRange = ActiveDocument.Paragraphs(11).Range
oWDRange.ExportFragment "D:\Documents and Settings\Admin\My Documents\Reference_11.docx", wdFormatDocumentDefault
End Sub
See alsoHow to export Word Range as RTF using VBA
- Login or register to post comments
- Feed: vbadb feed
- Original article
