Macro to replace styles used in tables (Word 2000/Windows)

Y

YEIREZQVBHEY

Hello,

While I have a pretty good grasp on recording macros, when it comes to
doing something like actual programming, I am in over my head!

I have found various code snippets in the groups and have tried to make
modifications, but haven't been particularly successful in my quest.
Here's what I'm trying to do:

I want to modify every table (and only tables) in a document so that
the first row is set to a particular style (TableHead), and all
remaining rows are set to another particular style (TableText).

Okay, that's not completely accurate. I do want to exclude the table on
the first page as well as the tables in the headers from this style
replacement.

The number of tables in the documents I need to modify can range from
no tables (other than the one on the first page and in the headers) or
up to 60 tables. The number of rows and columns will vary from table to
table and document to document. The same holds true for the styles
currently being used in the tables.

Currently working with Word 2000 for Windows running on Windows 2000.
Any advice or help will be greatly appreciated!

Dan
 
K

Klaus Linke

I want to modify every table (and only tables) in a document so that
the first row is set to a particular style (TableHead), and all
remaining rows are set to another particular style (TableText).

Okay, that's not completely accurate. I do want to exclude the table on
the first page as well as the tables in the headers from this style
replacement.


Hi Dan,

Something like

Dim i As Long
For i = 2 To ActiveDocument.Tables.Count
With ActiveDocument.Tables(i)
.Range.Style = ActiveDocument.Styles("TableText")
.Rows(1).Range.Style = ActiveDocument.Styles("TableHead")
End With
Next i

Greetings,
Klaus
 
K

Klaus Linke

Jezebel said:
That's very neat.

Yours too!
It will fail if the table contains any vertically merged cells,

That... and I assumed (perhaps wrongly) there's only one table on the first
page.
but it may be reasonable to assume that there are none such.

I can only hope so... but now, Dan has your macro as an alternative. And if we
both wrongly assumed something else we weren't even aware of, he'll hopefully
post back ;-)

Greetings,
Klaus
 
Y

YEIREZQVBHEY

Klaus and Jezebel,

I haven't had a chance to try either of your suggestions, but wanted to
thank you both. I will give them a try as soon as I get into work! :)
Thank you, thank you, thank you!

Dan
 
D

Dan

Just wanted to let you know that both of your macros have worked for me
in testing with various documents.

I can't adequately express how much this has helped me.
Thanks again!

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top