Word macros are slow since they are written in Basic.
But if you run a search and go make a cup of coffee, it
will probably be waiting for you when you come back.
If you use the advanced search criteria, some more
sophisticated searches are possible.=20
This is set up to show one line of context but you can
adjust that to suit your own needs by edited the macro.
This was originally done in the Chinese edition of Word
for two-byte Chinese characters. I revised it for English
but there are still Chinese characters in the macro. If
you don't have a Chinese system running, the Chinese
characters will appear as pairs of upper & lower ASCII
character. You will probably have to do a bit of adjusting
if you are not using Chinese Word to make the macro
suit your version of Word.
If anyone has any suggestions for improvement, please
let me know.
Sub MAIN
REM ***[This is the same as the Chinese version except for the length of =
the
line ]***
REM ***[This is printing one line of text for each hit. Chapter & page
numbers are]***
REM ***[ printed at end of line. Search string is in RED text.
]***
ViewZoom .ZoomPercent =3D 145
textwindow$ =3D WindowName$()
Activate textwindow$
REM text$ =3D FileName$()
FileNewDefault
ViewZoom .ZoomPercent =3D 95
REM ***[results file:]***
FileSaveAs .Name =3D "F:\CONCORD.CW7"
REM ***[Search file:]***
Activate textwindow$
REM FileOpen .Name =3D text$
REM StartOfDocument
REM ***[.Underline =3D 0 excludes underlines words (0 =3D exclude, 1 =3D =
include
only if,]***
REM ***[ -1 =3D either way) ]**=
*
REM EditFindClearFormatting
REM EditFindFont .Points =3D "", .Underline =3D 0, .Color =3D - 1, .Strik=
ethrough
=3D - 1, .Superscript =3D - 1, .Subscript =3D - 1, .Hidden =3D - 1, .Smal=
lCaps =3D -
1, .AllCaps =3D - 1, .Spacing =3D "", .Position =3D "", .Kerning =3D - 1,
.KerningMin =3D "", .Tab =3D "0", .Bold =3D - 1
' , .Italic =3D - 1, .FontMajor =3D "(=A5=FE=A7=CE=B2=C5=B8=B9)", .FontLo=
wAnsi =3D "(=A5=FE=A7=CE=B2=C5=B8=B9)",
.FontHighAnsi =3D "(=A5=FE=A7=CE=B2=C5=B8=B9)"
REM ***[This uses whatever search criteria is in the Edit Find dialog box=
]***
EditReplaceClearFormatting
EditFind
REM ***[Search string (between quotes in .Find =3D ""]***
REM ***[=AD=BB[!=B5=D9=A4Y] will not find =AD=BB=B5=D9 or =A7N=AD=BB=A4Y]=
***
REM ***[=AD=BB[=B5=D9=A4Y] will find only =AD=BB=B5=D9 and =A7N=AD=BB=A4Y=
]***
REM ***[PatternMatch =3D 1 (for advanced search criteria)]***
REM ***[.Format =3D 1 (to include EditFind formatting above)]***
REM EditFind .Find =3D "=AD=BB[!=B5=D9=A4Y]", .Direction =3D 0, .MatchCas=
e =3D 0, .WholeWord
=3D 0, .PatternMatch =3D 1, .SoundsLike =3D 0, .Format =3D 1, .Wrap =3D 2=
, .MatchByte =3D 1
While EditFindFound()
REM ***[copy instructions go here]***
REM ***[This grabs the line of the hit.]***
REM StartOfLine
REM EndOfLine 1
REM ***[This grabs 30 characters with the hit in the center]***
REM ***[ LINE LENGTH ]***
CharLeft 40
CharRight 85, 1
EditCopy
REM ***[move to end of selection to avoid a loop]***
CharRight 1
REM ***[moves cursor to beginning of selection and gets section and page
numbers]***
SelType 1=09
sectnum$ =3D Str$(SelInfo(2))
pagenum$ =3D Str$(SelInfo(3))
EndOfLine
REM ***[NextWindow (or filename for Document where results are stored)]*=
**
FileOpen .Name =3D " F:\CONCORD.CW7"
EndOfDocument
REM ***[If copying a line, the paragraph mark is in it already. Sometime=
s!]***
REM ***[This inserts a @ which will be converted to PM after unwanted PM=
s
are removed]***
Insert Chr$(64)
EditPaste
REM LineUp 1
REM CharLeft
REM ***[check out this section]***
EndOfLine
Underline 0
Insert " "
Insert "(" + LTrim$(sectnum$) + " -" + pagenum$ + ")"
=09
REM ***[PrevWindow (or filename of document where text is)]***
Activate textwindow$
REM FileOpen .Name =3D text$
CharRight
EditFind
Wend
REM ***[Results file]***
FileOpen .Name =3D " F:\CONCORD.CW7"
REM ***[Change all instances of search string in concordance to RED text]=
***
StartOfDocument
EditReplaceClearFormatting
EditReplaceFont .Color =3D 6
EditReplace .Replace =3D "", .ReplaceAll, .Format =3D 1
EditReplaceClearFormatting
EditReplace .Find =3D "^p", .Replace =3D " ", .ReplaceAll
EditReplace .Find =3D "@", .Replace =3D "^p", .ReplaceAll
EditReplace .Find =3D "^b", .Replace =3D " ", .ReplaceAll
EditReplace .Find =3D "^t", .Replace =3D " ", .ReplaceAll
Goto noChapterStyle
EditFindStyle .Style =3D "chapter"
EditReplaceStyle .Style =3D "Normal"
EditReplace .Find =3D "", .Replace =3D "", .ReplaceAll, .Format =3D 1
noChapterStyle:
REM ***[Change font]***
EditSelectAll
Font "Times New Roman", 11
StartOfDocument
End Sub
----------------------------------------------
David L. Steelman =ACI=C5K=A5=C1
English Department, Soochow University
P. O. Box 1840, Taipei 100 Taiwan
steelman@tp.globalnet.com.tw