Re: How can I automatically generate a list of acronyms in Word 97?

Subject: Re: How can I automatically generate a list of acronyms in Word 97?
From: Peter Collins <peter -dot- collins -at- BIGFOOT -dot- COM>
Date: Fri, 9 Oct 1998 00:36:47 +1000

Dear Lisa,
You say you do not write macros.
May I suggest, you should?
Why?
So many hard problems just fall into place, so easily.
I have used them to 'clean up' old heritage documents, inherited from
1980s WordPerfect versions, and for many other things that I can
detail if you want.
They are REALLY easy to get started on - and mostly they write
themselves (literally), at least for the substantive code.
Us humans have to put in the loops and exceptions..
Just make sure that you have Help for Visual Basic set up. thus:
Office 97 Setup, Add/Remove, Microsoft Word - Change Option, Help -
Change Option,
If Help For Visual Basic is already ticked, Cancel your way out,
otherwise select it, then OK your way out.

Now for a macro.
Suppose you wanted to undertline the third word after EVERY occurance
of the word 'this', in a huge doc-file, or in ANY selected doc-file.

* open or create a small doc with at least a few "this"s in it.
* Click Tools/Macro/Record
* Type in the name, say, "thisfix" and press <enter>
(A Stop Recording box displays and the cursor becomes a casette
symbol - this shows that whatever you do from now on will be
recorded - more about this later)
* Ctrl+<Home> (to go to start of document)
* Ctrl+f (find box displays)
* type "this"
* click <More button>
* click <find whole words only>
* select <Down> in the <Search> list
* Press <Enter> to start the search
* Press <Esc> when the search succeeds, to close the search
* Press Ctrl+<Right arrow> three times to the third word
* Press Ctrl+Shift+<Right Arrow>, release Ctrl (still holding down
Shift) press <Left Arrow> to highlight the whole word only.
* Press Ctrl+u to underline the word.
* Press <Right Arrow>
Now we have recorded the guts of the macro. It will find and change
just one occurance of the "this" case.
* Click the square symbol button in the Stop Recording box.

Now let's edit the macro to make the one occurance into a loop
* Press Alt+F8 to display the macro list.
* Click on <thisfix> in the list and click <Edit>
Unless I have totally stuffed up the instructions, you should see the
following macro text, which will initially find only one case of
"this" and requires only three changes to make it universal. I have
put the changes in already, marked with '*' comments, and I
describe the changes after this listing:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub thisfix()
'
' thisfix Macro
' Macro recorded 08/10/98 by Peter Collins
'
Selection.HomeKey Unit:=wdStory
Do '* [A] this line inserted later
Selection.Find.ClearFormatting
With Selection.Find
.Text = "this"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Not Selection.Find.Found Then End '*[C] inserted later
Selection.MoveRight Unit:=wdWord, Count:=3
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Selection.Font.Underline = wdUnderlineNone Then
Selection.Font.Underline = wdUnderlineSingle
Else
Selection.Font.Underline = wdUnderlineNone
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop While True '* [B] inserted later
End Sub
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
The changes are two extra lines to cause the whole thing to repeat
until all the "this" cases have been processed, and one to stop when
done.
These three lines are your foray into 'programming'.
A book on macros for Word97 would help,
The thing to remember is that one command line at a
time is executed unless defined otherwise by keyword sets such as <IF
condiftion then ... End IF> and <DO ... Loop While condition> which
alter
the flow based on whether some condition is true or not.
What we do is put a DO ... LOOP WHILE TRUE loop around the bits that
we want to repeat:
Interpretation: Repeatedly do everything that follows the "Do" [A]
down to the "LOOP", [B] while ever true is true - ie, until hell
freezes over.
But Word will tell you when it has searched the whole document and you
can reply that you do not want to continue searching, at which point the
line marked [C] does an 'End' as no further selection has been found
that matches what you sought to find.
(To discover what a term in a macro means, put your cursor on it and
press F1.)

To use the macro, select anywhere in your document,
then press Alt+F8 and double-click on 'thisfix'.

This macro contains at least one bug - it underlines punctuation
instead of words if the second word after a "this" has a trailing comma, say.
That's really the hard part of macro writing - testing and solving
exception cases.

buy a simple Macro book, and, have fun.
P
========================================================
Peter Collins, VIVID Management Pty Ltd,
26 Bradleys Head Road, MOSMAN 2088, Australia
+61 2 9968 3308, fax +61 2 9968 3026, mobile +61 (0)18 419 571
Management Consultants and Technical Writers
email: peter -dot- collins -at- bigfoot -dot- com ICQ#: 10981283
web pages: http://www.angelfire.com/pe/pcollins/
========================================================


From ??? -at- ??? Sun Jan 00 00:00:00 0000=



Previous by Author: Re: HELP! DComp doc tool in BPCS
Next by Author: Re: Designing a survey
Previous by Thread: Job Posting: Dallas, TX
Next by Thread: [no subject]


What this post helpful? Share it with friends and colleagues:


Sponsored Ads