A report generated by an old database program dumps everything out in one
long continuous file. That can not be changed. The resulting text file is
opened in Word, and the users run a macro I wrote that finds the first line
of each new record in the report and inserts a page break, so each new
record begins on a new page. All runs well - until someone changes that
first line! It's hard-coded into the macro as the string for "Find.Text =
strFind". Then, of course, it's my macro that's broke!

The header for each new record in the report has four lines. Each line is a
separate paragraph. Each line will report the same item of information,
such as:
ITEM NO: SER NO:
COLOR: BIN NO:
The information at each label may or may not change, but these labels will
remain fixed at their character positions in each line at each report
header. (For instance, whether COLOR: is "blue" or "chartreuse", the BIN
NO: label will always be at the same character position.)

Is there an easy way to tell the macro to "find three or four paragraphs
with these labels at these character positions", while disregarding whatever
information may be presented at the label?

Ed

RE: "Find this, insert page break": what approach? by kbackmann

kbackmann
Wed Jan 18 08:30:03 CST 2006

Maybe this would work or point in the general direction:

Sub FindStuff()

Dim strLine As String
Dim rng As Range
Dim blnDone As Boolean

'Move to start of document
Selection.HomeKey unit:=wdStory

'Loop through the document, looking on each line for
'either "Test Text" or "Indented Text"
Do Until blnDone = True
'Select each line and verify that the end of the document
'has not been reached. If not, search for indicated text
With Selection
.HomeKey unit:=wdLine
.EndKey unit:=wdLine, Extend:=wdExtend
If .End = ActiveDocument.Content.End Then blnDone = True
strLine = .Text
End With
'If the text is found, insert page break
If InStr(1, strLine, "Test text") > 1 Or InStr(1, strLine, "Indented
Text") > 1 Then
Selection.HomeKey unit:=wdLine
Selection.InsertBreak Type:=wdPageBreak
End If
Selection.MoveDown unit:=wdLine
Loop

End Sub

--
Kevin Backmann


"Ed" wrote:

> A report generated by an old database program dumps everything out in one
> long continuous file. That can not be changed. The resulting text file is
> opened in Word, and the users run a macro I wrote that finds the first line
> of each new record in the report and inserts a page break, so each new
> record begins on a new page. All runs well - until someone changes that
> first line! It's hard-coded into the macro as the string for "Find.Text =
> strFind". Then, of course, it's my macro that's broke!
>
> The header for each new record in the report has four lines. Each line is a
> separate paragraph. Each line will report the same item of information,
> such as:
> ITEM NO: SER NO:
> COLOR: BIN NO:
> The information at each label may or may not change, but these labels will
> remain fixed at their character positions in each line at each report
> header. (For instance, whether COLOR: is "blue" or "chartreuse", the BIN
> NO: label will always be at the same character position.)
>
> Is there an easy way to tell the macro to "find three or four paragraphs
> with these labels at these character positions", while disregarding whatever
> information may be presented at the label?
>
> Ed
>
>
>

Re: "Find this, insert page break": what approach? by Ed

Ed
Wed Jan 18 09:08:01 CST 2006

Good idea! Use InStr to return the position of the text strings, and I can
repeat that as much as needed to confirm I am where I need to be. Thanks
Kevin.

Ed

"Kevin B" <kbackmann@sbcglobal.net.spamBgone> wrote in message
news:BEF42B25-F430-47D5-B9A2-A299344F491A@microsoft.com...
> Maybe this would work or point in the general direction:
>
> Sub FindStuff()
>
> Dim strLine As String
> Dim rng As Range
> Dim blnDone As Boolean
>
> 'Move to start of document
> Selection.HomeKey unit:=wdStory
>
> 'Loop through the document, looking on each line for
> 'either "Test Text" or "Indented Text"
> Do Until blnDone = True
> 'Select each line and verify that the end of the document
> 'has not been reached. If not, search for indicated text
> With Selection
> .HomeKey unit:=wdLine
> .EndKey unit:=wdLine, Extend:=wdExtend
> If .End = ActiveDocument.Content.End Then blnDone = True
> strLine = .Text
> End With
> 'If the text is found, insert page break
> If InStr(1, strLine, "Test text") > 1 Or InStr(1, strLine,
"Indented
> Text") > 1 Then
> Selection.HomeKey unit:=wdLine
> Selection.InsertBreak Type:=wdPageBreak
> End If
> Selection.MoveDown unit:=wdLine
> Loop
>
> End Sub
>
> --
> Kevin Backmann
>
>
> "Ed" wrote:
>
> > A report generated by an old database program dumps everything out in
one
> > long continuous file. That can not be changed. The resulting text file
is
> > opened in Word, and the users run a macro I wrote that finds the first
line
> > of each new record in the report and inserts a page break, so each new
> > record begins on a new page. All runs well - until someone changes that
> > first line! It's hard-coded into the macro as the string for "Find.Text
=
> > strFind". Then, of course, it's my macro that's broke!
> >
> > The header for each new record in the report has four lines. Each line
is a
> > separate paragraph. Each line will report the same item of information,
> > such as:
> > ITEM NO: SER NO:
> > COLOR: BIN NO:
> > The information at each label may or may not change, but these labels
will
> > remain fixed at their character positions in each line at each report
> > header. (For instance, whether COLOR: is "blue" or "chartreuse", the
BIN
> > NO: label will always be at the same character position.)
> >
> > Is there an easy way to tell the macro to "find three or four paragraphs
> > with these labels at these character positions", while disregarding
whatever
> > information may be presented at the label?
> >
> > Ed
> >
> >
> >