Hi rocket,
Here's some code to get you started. It assumes that you're looking for a
string of text that starts with "PO" and ends with a blank line (two
paragraph marks in a row). If your "blank" lines aren't created with two
paragraph marks in a row, you may need to edit the following line, where it
appears in the subroutine:
.Text = "PO*^13^13"
Here's the subroutine:
Sub CopyPortionsOfDocToNewDoc()
'Setup variables
Dim CurrentDoc As Document
Dim NewDoc As Document
Dim EndOfNewDoc As Range
'set CurrentDoc to represent the current document
Set CurrentDoc = ActiveDocument
'set up a find operation to use wildcards and to search
'for a string starting with PO and ending with two
'sequential paragraph marks (representing an empty row)
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "PO*^13^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'perform the find operation
Selection.Find.Execute
'as long as the find operation is successful,
'continue to repeat it
While Selection.Find.Found()
'first time through, add a new doc
If NewDoc Is Nothing Then
Set NewDoc = Documents.Add()
CurrentDoc.Activate
End If
'copy the found text to the new document
Set EndOfNewDoc = NewDoc.Range
EndOfNewDoc.Collapse wdCollapseEnd
EndOfNewDoc.FormattedText = Selection.Range
Selection.Collapse wdCollapseEnd
'repeat the find operation
Selection.Find.Execute
Wend
'activate the new doc, if it exists, so
'user can see results
If Not NewDoc Is Nothing Then
NewDoc.Activate
Else
MsgBox "Targeted text not found."
End If
End Sub
HTH
--
Bill Coan
Templates, wizards, add-ins, and macros for Word
For more information, visit: www.wordsite.com
Quote:
Quote:
> I need to extract sections of text from a 400 page + document the sections
> of text have blank lines in between them and they can be 17 lines long to
21
> lines long.
> So to copy out the text I need to find the start of the text and then the
> blank line, therefore I need to know firstly where the text starts (it
> always starts PO) then find the blank line blow the last piece of text and
> copy this to a new document
> Ron
> > Hi Rocket,
> > > I am trying to write a macro so that I can extract paragraphs of text
> from a
> > > very a very long document trouble is I need to get the current cursor
> > > position from somewhere any idea what returns it
> > Can you be more specific, what information you want to return? Do you
want
> a
> > page number, or what?
> > Cindy Meister
> > INTER-Solutions, Switzerland
> > http://homepage.swissonline.ch/cindymeister
> > http://go.compuserve.com/MSOfficeForum
> > This reply is posted in the Newsgroup; please post any follow question
or
> > reply in the newsgroup and not by e-mail :-)