![]() |
|
#1
|
|||
|
|||
![]() This code allows the 11th paragraph of a document to be extracted and exported. It could of course be the 29th or 9th. But is it possible to use ExportFragment with a range that is, say, all the text between 2 specific words? Or all paragraphs beginning with a particular word or phrase? I am wondering how flexible it is, or whether it can only be used in the way set out in this code. Thanks. Code:
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 |
#2
|
||||
|
||||
![]()
You can export as much or as little as you want. However, whatever you export must be a contiguous range, not multiple separate ranges. For example, the following code could be used to export all fragments beginning the 'Start' and ending with 'End' to new documents:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "Start*End" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWildcards = True .Execute End With Do While .Find.Found i = i + 1 .Duplicate.ExportFragment "D:\Documents and Settings\Admin\My Documents\Fragment_" _ & Format(i, "00") & ".docx", wdFormatDocumentDefault .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True MsgBox i & " fragments exported." End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Thanks, Paul. That's very helpful.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Semi-flexible templates (couple of questions) | mshanks | Word | 1 | 07-29-2009 06:35 AM |