Shauna
Fri Aug 04 20:00:32 CDT 2006
Hi trgobeille
One way to achieve your aim here is to re-think the process. Instead of
copying the text from the body to the bottom of the document, it would be
much easier to mark in the text what's required in the list at the bottom of
the document, and then generate that list.
To do that, you can use Word's table of contents functionality. Get Word to
create a table of contents that consists only of the paragraphs marked with
a certain style. And, tell Word to omit the page numbers from the table of
contents.
So the first thing to consider is what styles have been used in the
document. If the document is all in one style, then you could create a new
style and call it something like "Summary". Base it on Normal or whatever
style is used in the document for ordinary text. That is, it can *look* just
like the surrounding text.
For the "LAUNCH DATE" and "DETAILS" paragraphs, you can use Edit > Replace
to search for your text and replace it with the same text, but with your new
style. (Click in the "Replace with" box, type the replacement text, which is
the same as the find text, click More and select your style.)
Now, at the bottom of the document, type the following (be careful of where
the spaces go):
TOC \t "Summary,1" \n"1-1"
Select all that, and do (in the following order): ctrl-F9, F9, Shift-F9.
That will give you a 'table of contents' of all the text you marked with
your Summary style. At the very end of the process, if you need the list to
be plain text, you can convert the
field. Put your cursor in the 'table of contents' and do ctrl-Shift-F9.
So far, it's taken longer to explain this than it will to do it!
However, that won't cope with the need to get the paragraph *after* the
'START REPORT' text. Is there some other way you can easily identify the
paragraphs you need in your list, so you could search for some specific text
and apply your Summary style to that? If not, then you'll need a macro.
Here's a simple one that goes through the document, and applies the Summary
style to every paragraph *after* a paragraph containing "START REPORT"
Sub MarkParaAfterStartReportAsSummary()
Dim wdStyle As Word.Style
Dim oRange As Word.Range
'Make sure that there's a style called "Summary"
On Error Resume Next
Set wdStyle = ActiveDocument.Styles("Summary")
On Error GoTo 0
If wdStyle Is Nothing Then
Set wdStyle = ActiveDocument _
.Styles.Add("Summary")
wdStyle.BaseStyle = wdStyleNormal
End If
'Display field codes, not results
ActiveWindow.View.ShowFieldCodes = True
'Find all text that says "START REPORT"
Set oRange = ActiveDocument.Content
With oRange
.Find.ClearFormatting
With .Find
.Text = "START REPORT"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While .Find.Execute
'If this is not in a field,
'apply the Summary style to the
'*next* paragraph
If Not oRange.Paragraphs(1).Range.Fields.Count > 0 Then
oRange.Move wdParagraph, 1
oRange.Style = "Summary"
End If
Loop
End With
'Display field results
ActiveWindow.View.ShowFieldCodes = False
End Sub
Hope this helps.
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
<trgobeille@gmail.com> wrote in message
news:1154729643.462020.178220@s13g2000cwa.googlegroups.com...
>I have a Word document that contains hundreds of similarly-formatted
> reports (about 30-40 lines of text with carriage returns), with lines
> that flag the start of each report and lines that are specifically
> flagged that I need to copy and paste at the bottom of the document.
> What I need to do is activate a macro that looks for the first start
> flag ("START REPORT"), copies the line of text underneath it, then
> looks for rows flagged as "LAUNCH DATE" and "DETAILS", copies those,
> and then dumps all four rows of text at the bottom of the document.
> Then, finds the next report (within the document) and repeats the
> process until it hits the end of the document.
>
> Any thoughts would be greatly appreciated. Thanks!
>