Word Experts,
I have written code in Excel VBA and now need to do a few tasks in Word VBA.
I could use some help figuring out a few basics.
Each day I have to print a section of a report that falls in the middle of
the report.
A simplified version of the report is provided below. I have to print from
the line that begins with "ACCOUNT: X435" through the line "PREM POT
9,051,419".
Using the macro recorder, I've tried to create code but I seem to have a few
things wrong.
<<Begin Report>>
THE FOREGOING INFORMATION IS
/PAGE
ACCOUNT: X435
NET CAPITAL
ACCT EQUITY
---- ------------ ---
4AM0 -38,789
4K3E -463,046
PREMIUM POTENTIAL
PREM POT 9,051,419
(1) DIVIDENDS PAYABLE OR
(2) IF POSITIONS ARE IN MORE
<<End Report>>
I've tried to write the code by:
1) searching for the first key word which marks the beginning of the section
I want to print,
2) assigning a variable to the result of the first search,
3) searching for the second key word,
4) assigning a variable to the result of the second search
5) selecting the text starting with the first variable and ending with the
second variable
6) printing the selection
It runs through the code until it gets to the "Application.PrintOut" line at
the bottom, although I'm don't think I was successful at assigning any of the
variables.
Your help would be appreciated. Thanks, Alan
Sub PrintSection()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "ACCOUNT: X435"
.Forward = True
End With
Selection.Find.Execute
Set StartPrint = Selection
Selection.HomeKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "prem pot"
.Forward = True
End With
Selection.Find.Execute
Set EndPrint = Selection
Set rngPrint = ActiveDocument.Range(StartPrint.Words(1).Start,
EndPrint.Words(2).End)
Application.PrintOut FileName:="", Range:=rngPrint
End Sub

Signature
achidsey
Doug Robbins - Word MVP - 18 Nov 2005 05:28 GMT
Dim prange As Range
Set prange = ActiveDocument.Range
prange.Start = prange.Start + InStr(prange, "ACCOUNT") - 1
prange.End = prange.Start + InStr(prange, "PREM POT") + 21
prange.Select
ActiveDocument.PrintOut Range:=wdPrintSelection

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Word Experts,
>
[quoted text clipped - 81 lines]
>
> End Sub
achidsey - 18 Nov 2005 21:31 GMT
Doug,
Thanks for your help.
Alan

Signature
achidsey
> Dim prange As Range
> Set prange = ActiveDocument.Range
[quoted text clipped - 88 lines]
> >
> > End Sub