Tables and adding columns
I have a large MS Word document that is created from another program. It creates a table on one page that needs to be modified everytime. This might be the 10th or 20th table in the file. I want to have a macro look for the word "Work" and when it is found go to the next table and take the 3 right columns and copy them and paste them right next to what is there. Then I need it to change the heading cells in the 3 copied columns.
Next to make this even more complex there is another table that is always underneith this one and I need it to just copy the right 2 columns and paste them on the right of that table.
The columns that are filling in have room enough to the right for the extra cells to be pasted in without any issue of going off of the page.
I appreciate your assistance in this. I do a lot of VBA in excel and word is new to me.
Thank you,
Jake
[907 byte] By [
Bigjaker] at [2007-11-20 10:12:53]

# 1 Re: Tables and adding columns
Well I figured this out on my own. Thought that once I got an answer I would post it so others can learn. Below is the macro that I used. After getting started I decided I can live with a few changes to the way I had originally wanted it to run. I now have 2 macros one for each table type. It doesn't copy the information from the columns on the left into the columns on the right. Would have been nice but since the numbers will be changing no real point for it.
This might not be perfect but it gets the job done. Let me know if you have any questions or comments.
Sub Table1()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Work"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
While Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=3, Extend:=wdExtend
Selection.InsertColumnsRight
Selection.TypeText Text:="Current Payroll"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Current Rate"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Current Premium"
Selection.Tables(1).Columns(6).SetWidth ColumnWidth:=68.4, RulerStyle:= _
wdAdjustNone
Selection.Tables(1).Columns(7).SetWidth ColumnWidth:=64, RulerStyle:= _
wdAdjustNone
Selection.Tables(1).Columns(8).SetWidth ColumnWidth:=70, RulerStyle:= _
wdAdjustNone
Wend
End Sub