F
fjghny
Hi, I have a question about a table macro I’m trying to create. I know there are probably much better ways of doing it, but I’m just not very good at VBA, and what I have seems to work, except for the very last line of code. What the macro is supposed to do is take a table that has three columns but has the cells in the top row merged. It splits the table into two halves so that the three columns can be sized, then the top row with the merged cells can be sized, and then the paragraph mark separating the two halves of the table is deleted to join the table back together again. It seemsto work fine except when it gets to the very last line of code that deletes the paragraph mark separating the two tables. Once they are joined together, the table reverts back to its previous width. I can just remove the last line of code and join the table manually after the macro has been run, but it’s kind of annoying and it’s also puzzling to me as to why the table reverts back just because it is joined together again. Can anyone shedany light on this or tell me another way of doing this so that I don’t have this problem? Thanks in advance for any information. The macro I’vecreated is below.
Sub TEST()
Selection.Tables(1).Rows(2).Select
Selection.SplitTable
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Columns(1).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1)
Selection.Tables(1).Columns(2).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1)
Selection.Tables(1).Columns(3).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(2.3)
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.Tables(1).Columns(1).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(4.3)
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
Sub TEST()
Selection.Tables(1).Rows(2).Select
Selection.SplitTable
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Columns(1).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1)
Selection.Tables(1).Columns(2).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(1)
Selection.Tables(1).Columns(3).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(2.3)
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.Tables(1).Columns(1).Select
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = InchesToPoints(4.3)
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub