Repeat macro until end of document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I apologize if there is an easy answer for this - I have looked all over and
cannot find one anywhere.

How do I get a macro to repeat until it reaches the end of the document, at
which point it terminates?

I have a document with a large number of similarly formatted tables. I am
trying to perform a number of formatting changes with macros (e.g., resize
columns, change borders, move columns). There are cases in which it ruins
the table if the macro goes back to the beginning of the document and
reapplies itself to tables it has already altered (e.g., moving a column a
second time).

I am working in Word 2000 and Windows 2000.

Please let me know if you need more specific information than this to
provide an answer.

Thanks!
 
I apologize if there is an easy answer for this - I have looked all over and
cannot find one anywhere.

How do I get a macro to repeat until it reaches the end of the document, at
which point it terminates?

I have a document with a large number of similarly formatted tables. I am
trying to perform a number of formatting changes with macros (e.g., resize
columns, change borders, move columns). There are cases in which it ruins
the table if the macro goes back to the beginning of the document and
reapplies itself to tables it has already altered (e.g., moving a column a
second time).

I am working in Word 2000 and Windows 2000.

Please let me know if you need more specific information than this to
provide an answer.

Thanks!

Hi Chris,

The general answer is to edit the macro so that it contains a loop,
which repeats the formatting steps for each table in the document. The
loop actually uses that language:

Dim MyTable As Table
For Each MyTable In ActiveDocument.Tables
' do the formatting of MyTable
Next MyTable

The 'do the formatting' could consist of calls to macros that already
exist, if they're written to be called that way (but macros that you
record aren't written that way...).

If you need more help than that, I think you should be asking in the
Programming group (which is actually the newsgroup
microsoft.public.word.vba.beginners).
 
Back
Top