I'm trying to write a silly little macro that goes to every table in an
active document, looks for a particular style, then sets that selection
to 9 points. I have this:

For Each aTable In ActiveDocument.Tables
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Note")
Selection.Style.Font.Size = 9


Obviously it doesn't work (or I wouldn't be here). When I run this
macro it seems to change whatever style the cursor happens to be at at
the time it starts, from that point forward. it never even seems to get
"into" the tables. If i have the cursor inside a table when i run the
macro it seems to do what i want. I need this to be an auto-open macro.


Any advice? Thanks.

Re: looping to change a font size by Jay

Jay
Fri Nov 18 10:09:02 CST 2005

Lighthouse wrote:
> I'm trying to write a silly little macro that goes to every table in
> an active document, looks for a particular style, then sets that
> selection to 9 points. I have this:
>
> For Each aTable In ActiveDocument.Tables
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Note")
> Selection.Style.Font.Size = 9
>
>
> Obviously it doesn't work (or I wouldn't be here). When I run this
> macro it seems to change whatever style the cursor happens to be at at
> the time it starts, from that point forward. it never even seems to
> get "into" the tables. If i have the cursor inside a table when i run
> the macro it seems to do what i want. I need this to be an auto-open
> macro.
>
>
> Any advice? Thanks.

If the style named Note occurs only in tables, or if you want it to be 9 pt
wherever it occurs, then what you want to do is NOT a find but just to
modify the style:

Sub AutoOpen()
On Error Resume Next ' in case Note doesn't exist
ActiveDocument.Styles("Note").Font.Size = 9
End Sub

If the style is used both inside and outside tables, and you want the text
in that style to be overridden with direct formatting of 9 pt size, then you
need something more complicated -- but I don't want to get into that if you
don't need it.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



Re: looping to change a font size by Tony

Tony
Fri Nov 18 10:13:11 CST 2005

You must Execute the Find - all that shows in your code snippet is
(partially) setting it up

For Each aTable In ActiveDocument.Tables
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Note")

Selection.Find.Execute

Selection.Style.Font.Size = 9

There is, of course, more to it. You should check whether the Find has
actually found anything. One way is to check the return from the Find ...

For Each aTable In ActiveDocument.Tables
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Note")

If Selection.Find.Execute Then

Selection.Style.Font.Size = 9
' etc.

The next thing you need to be aware of is that although you have a For Each
loop, your Find is working on the Selection. It would be better done on the
individual table ..

aTable.Range.Find.ClearFormatting
' etc.

--
Enjoy,
Tony


"Lighthouse" <gruntledlark@gmail.com> wrote in message
news:1132327223.250314.135640@g43g2000cwa.googlegroups.com...
> I'm trying to write a silly little macro that goes to every table in an
> active document, looks for a particular style, then sets that selection
> to 9 points. I have this:
>
> For Each aTable In ActiveDocument.Tables
> Selection.Find.ClearFormatting
> Selection.Find.Style = ActiveDocument.Styles("Note")
> Selection.Style.Font.Size = 9
>
>
> Obviously it doesn't work (or I wouldn't be here). When I run this
> macro it seems to change whatever style the cursor happens to be at at
> the time it starts, from that point forward. it never even seems to get
> "into" the tables. If i have the cursor inside a table when i run the
> macro it seems to do what i want. I need this to be an auto-open macro.
>
>
> Any advice? Thanks.
>