Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-26-2019, 08:29 PM
Guessed's Avatar
Guessed Guessed is offline Top row of table not selecting in code Windows 10 Top row of table not selecting in code Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top row of table not selecting in code Code to find a named (bookmarked?) table, replicate a row or table, and delete a specified table. kevinbradley57 Word VBA 9 09-21-2017 04:58 PM
Top row of table not selecting in code Problem with table grid when selecting status in ribbon lodi123 Word VBA 1 02-24-2017 05:32 AM
Selecting a digit from a code Warren99 Excel 2 05-29-2016 04:08 AM
Top row of table not selecting in code Selecting table cell vs. text dionnaro Word Tables 1 05-24-2016 04:04 PM
Selecting/deselecting items in pivot table mbesspiata Excel 0 07-22-2014 08:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:51 PM.


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