![]() |
|
#1
|
|||
|
|||
|
I have many table with a title directly above the table. This code below works just fine to add that header as part of the table in the newly created row 1; however, I just ran into a table that has vertically merged cells and therefore throwing an error when running the code.
I know merge cells are not ideal, but in this situation they will have to remain. Is there a way to access the table even with the merged cells and still add the text above the table as the title in row 1? In the attachment there is a before and after? Code:
Sub CleanupTables()
Dim aTbl As Table
Dim aRng As Range
Dim aRow As Row
Application.ScreenUpdating = False
For Each aTbl In ActiveDocument.Tables
Set aRng = aTbl.Range
aRng.MoveStart Unit:=wdParagraph, Count:=-1
aRng.Select
ActiveWindow.ScrollIntoView aRng, True
With aTbl
If MsgBox("Does this table have a table name", vbYesNo) = vbYes Then
Set aRow = aTbl.Rows.Add(BeforeRow:=aTbl.Rows(1))
aRow.Range.Cells.Merge
Set aRng = aRng.Paragraphs(1).Range
aRng.MoveEnd Unit:=wdCharacter, Count:=-1
aRow.Range.Cells(1).Range.FormattedText = aRng.FormattedText
aRng.Paragraphs(1).Range.Delete
aRow.Borders(wdBorderTop).LineStyle = wdLineStyleNone
aRow.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
aRow.Borders(wdBorderRight).LineStyle = wdLineStyleNone
aRow.Range.Style = "Caption"
aRow.Range.ParagraphFormat.Reset
End If
End With
Next aTbl
Application.ScreenUpdating = True
End Sub
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Want to copy & paste a table underneath itself x no. of time, table found through style heading name
|
fly545 | Word VBA | 11 | 01-16-2020 05:53 PM |
| Can I create a page number from a non-Heading style? | techwriter3k | Word | 9 | 09-25-2019 06:58 AM |
| Deleting Blank Space between table heading and table rows | Pete Jones | Word Tables | 5 | 01-22-2018 04:11 PM |
Heading row disappears from table styles when pasted table is selected
|
andrewballem | Word Tables | 2 | 11-12-2013 05:18 AM |
Create and save custom heading style
|
ubns | Word | 3 | 08-01-2012 09:42 PM |