View Single Post
 
Old 11-26-2019, 08:29 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You should be using a style to apply to the caption rather than doing a local format for bold. Working code might be along the lines of the following
Code:
Sub UpdateTables2()
    Dim rng         As Range
    Dim aTbl As Table
    Dim aRow As Row
    Dim x           As Long
    Dim MyTables    As Long: MyTables = ActiveDocument.Tables.Count
    Dim MyNote      As String: MyNote = "Does this table have a table name"
    Dim answer      As String
    Dim aRng As Range
    
    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
      
      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"
    Next aTbl
    Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote