On 18/07/07, Andrew Douglas Pitonyak <[EMAIL PROTECTED]> wrote:

Mitchel Cohen wrote:
> How do I embed a macro inside itself, so that it repeats the action
> and doesn't just perform one occurrence?
>
> In other words, I want to add an opening "<" to every occurrence of an
> email address on a long list. I've developed a simple macro to do that
> for the first occurrence, but then I have to hit "run macro" each time
> I want it to continue. How do I get the macro to do this automatically?
>
> Thanx.
>
> Mitchel Cohen
>
Assume that your macro is called "DoIt()". I could write another macro

Sub DoIt100Times()
  Dim i As Integer
  For i = 1 To 100
    DoIt()
  Next
End Sub


You could even ask how many times to do the loop and then run it the
requested number of times. More than likely, however, you want to
iterate over your text and do the loop until everything is finished,
which is more difficult because you need to understand how to check this
in your macro. As a quick solution, I usually do something like the
DoIt100Times, or I keep my Main() macro as the first macro in the
module. I then modify main as follows:

sub Main()
  DoIt()
End Sub

In the IDE, the first macro in the current module is run by pressing the
"run icon". I can then keep clicking the run macro button until it is
finished.


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Seems to me you might not even need a macro but instead might be able to use
OO's Regular Expression feature within Find and Replace.

If we assume you have one entry per line with each entry being lastName
firstName emailAddress thus
Smith John [EMAIL PROTECTED]
Doe Jane [EMAIL PROTECTED]
Robinson Hilary [EMAIL PROTECTED]

Then, go to Find and Replace, click on More Options and check the Regular
Expressions box. Now:
in the Find box enter " .* " without the quotes; that's space dot asterisk
space
in the Replace box enter "&<" again without the quotes; that's ampersand
less-than
Now click Replace All and bingo, a "<" will be appended to the person's
first name i.e. it will be *prepended* to the e-mail address.

For a few details about Regular Expressions, read Writer's Help under
Regular Expressions. For much more, read the chapters in a perl book about
them or, on *nix, do "man grep" or "man egrep". Google will yield zillions
of references.

Basically you are *finding* a space followed by any number of any character
followed by a space (in this case the person's first name) and "replacing"
whatever was found by itself followed by a "<".

If your data are formatted differently you may need to modify what you enter
into the Find and/or Replace boxes but the chances are high that Regular
Expressions will do the job for you.

--
Harold Fuchs
London, England
Please reply *only* to [email protected]

Reply via email to