Macro to copy certain reports from a large word doc.

A

angellijah

Question

I have a large doc with multiple reports which I have to extract certain
reports from on a weekly basis. Is there a macro that can help? Dave had
responded with another question, so I wanted to repost the question with the
additional information.

Hi,
The answer is Most Likely, but we'll only be able to help if we have more
information.

How many reports?
Always the same ones?
What are the "starting" and "ending" points for each report?
Are there any significant attributes of the report (for example, each report
is a table)?

Dave

The reports always have the same names, though the number of pages vary.
The
report name is listed at the top of each page of each report. Each report
ends with some sort of "totals" or "grand totals" information, but that
varies between reports. I am saving each part of the report as a .txt file,
so I don't need any fancy formatting. There is also a page # title (SARPAGE
1, SARPAGE 2, etc.) at the top of each report page throughout the entire
document. The pages of each report do not necessarily end and start in the
same place as where the page breaks in Word
 
D

DaveLett

Hi,
Based on the information that you've provided, this is as close as I can come:
Dim vReports As Variant
Dim oRng As Range
Dim lCount As Long

vReports = Array("Report1", "Report2")

Selection.Find.ClearFormatting

For lCount = LBound(vReports) To UBound(vReports)
With Selection
.HomeKey Unit:=wdStory
With .Find
.Text = vReports(lCount)
If .Execute Then
Set oRng = Selection.Range
Do While LCase(oRng.Words.Last.Text) <> "totals"
oRng.MoveEnd Unit:=wdWord, Count:=1
Loop
'''now, if these conditions are correct,
'''you have your report; it's oRng
End If
End With
End With

Next lCount


HTH,
Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top