Reply
 
Thread Tools Display Modes
  #1   Report Post  
 
Posts: n/a
Default Macro to replace styles used in tables (Word 2000/Windows)

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

  #2   Report Post  
Jezebel
 
Posts: n/a
Default

The code might look something like this --

Dim pTable as Word.Table
Dim pCell as Word.Cell

For each pTable in ActiveDocument.Tables

If pTable.Range.Information(wdActiveEndPageNumber) 1 then

Set pCell = pTable.Cell(1,1)

Do
If pCell.RowIndex = 1 then
pCell.Range.Style = "TableHead"
Else
pCell.Range.Style = "TableText"
End if

Set pCell = pCell.Next

Loop until pCell is nothing
End if

Next




wrote in message
oups.com...
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



  #3   Report Post  
Klaus Linke
 
Posts: n/a
Default

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


  #4   Report Post  
Jezebel
 
Posts: n/a
Default

That's very neat. It will fail if the table contains any vertically merged
cells, but it may be reasonable to assume that there are none such.


"Klaus Linke" wrote in message
...
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




  #5   Report Post  
Klaus Linke
 
Posts: n/a
Default

Jezebel wrote:
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




  #6   Report Post  
 
Posts: n/a
Default

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

  #7   Report Post  
Dan
 
Posts: n/a
Default

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

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic macros query - where are they assigned to? Bert Coules New Users 15 January 18th 05 12:28 PM
How do I create & merge specific data base & master documents? maggiev New Users 2 January 12th 05 11:30 PM
word xp crashes after macros are recorded kharris0405 Microsoft Word Help 3 January 11th 05 10:50 PM
WP Delay Code - Word Equiv Mike G - Milw, WI Microsoft Word Help 6 January 10th 05 04:12 PM
How to change merge forms from Word Perfect to Microsoft Word dollfindance Microsoft Word Help 2 December 30th 04 03:35 PM


All times are GMT +1. The time now is 04:51 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"