Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-07-2019, 01:52 PM
jeffreybrown jeffreybrown is offline Create heading row for table Windows 10 Create heading row for table Office 2016
Expert
Create heading row for table
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Create heading row for table

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
Attached Files
File Type: docm Table 1.docm (26.2 KB, 12 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create heading row for table 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
Create heading row for table Heading row disappears from table styles when pasted table is selected andrewballem Word Tables 2 11-12-2013 05:18 AM
Create heading row for table Create and save custom heading style ubns Word 3 08-01-2012 09:42 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft