Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-15-2019, 04:45 PM
jeffreybrown jeffreybrown is offline Format tables with vertically merged cells Windows Vista Format tables with vertically merged cells Office 2007
Expert
Format tables with vertically merged cells
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Format tables with vertically merged cells

I'm fixing some word products which already have some tables with vertically merged cells.



The macro works fine, but when encountering the tables with the vertically merged cells, getting the error.

Quote:
Cannot access individual rows in this collection because the table has vertically merged cells.
Is this possible to overcome without unmerge those vertically merged cells?

Code:
Sub FormatFirstTableRow()
    Dim Tbl As Table
    Dim i As Long
    Dim iRow As Row
    Application.ScreenUpdating = False
    For Each Tbl In ActiveDocument.Tables
        With Tbl
            .Rows(1).Select
            If InStr(1, Selection.Text, "Table") = 1 Or InStr(1, Selection.Text, "Figure") = 1 Then
                With .Rows(1)
                    .Range.Style = "TblHeader"
                    .Borders.Enable = False
                    .Borders(wdBorderBottom).LineStyle = Options.DefaultBorderLineStyle
                    .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
                End With
                .AutoFitBehavior (wdAutoFitContent)
                .Rows.HeightRule = wdRowHeightExactly
                .Rows.Height = InchesToPoints(0.2)
            End If
        End With
    Next
    ActiveDocument.Fields.Update
    Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 01-15-2019, 08:57 PM
Guessed's Avatar
Guessed Guessed is online now Format tables with vertically merged cells Windows 10 Format tables with vertically merged cells Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
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

Try something like the following, whereby I loop across the cells until I hit the second row
Code:
Sub FormatFirstTableRow2()
  Dim Tbl As Table, i As Long, iRow As Row, sCellText As String, aCell As Cell
  Application.ScreenUpdating = False
  For Each Tbl In ActiveDocument.Tables
    With Tbl
      sCellText = Trim(.Range.Cells(1).Range.Words(1))
      If sCellText = "Table" Or sCellText = "Figure" Then
        For Each aCell In .Range.Cells
          If aCell.RowIndex > 1 Then Exit For
          aCell.Range.Style = "TblHeader"
          aCell.Borders.Enable = False
          aCell.Borders(wdBorderBottom).LineStyle = Options.DefaultBorderLineStyle
          aCell.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
        Next aCell
        .AutoFitBehavior (wdAutoFitContent)
        .Rows.HeightRule = wdRowHeightExactly
        .Rows.Height = InchesToPoints(0.2)
      End If
    End With
  Next
  ActiveDocument.Fields.Update
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 01-16-2019, 03:23 PM
jeffreybrown jeffreybrown is offline Format tables with vertically merged cells Windows Vista Format tables with vertically merged cells Office 2007
Expert
Format tables with vertically merged cells
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Thank you Andrew. This did the trick.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unmerging vertically merged cells kilroy Word VBA 5 01-12-2018 12:54 PM
VBA color of visible gridlines of tables word (with some merged cells in first rows) Alvaro.passi Word VBA 0 07-18-2017 09:11 AM
Format tables with vertically merged cells Overcome issues in tables with vertically merged cells rocky2 Word VBA 12 12-22-2016 03:03 AM
Format tables with vertically merged cells How to vertically align a merged cell to fit text paik1002 Excel 6 09-20-2016 03:00 AM
Combining 2 tables into 1 and use Table2's column widths (hoping for workaround dealing merged cells CodingGuruInTraining Word VBA 24 10-07-2015 07:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:52 PM.


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