![]() |
|
#1
|
|||
|
|||
![]()
Hi,
Thanks for the response. There are some issues like table has not having same inner grid lines which do not print for each cell borders. some cells have inner grid which do not print and some cells might not have. I have tried the below code to encounter the two errors while executing a macro: 1. Requested member of the collection does not exist error at For j = 1 To tbl.Rows(i).Cells.count 2. cannot access individual rows in this collection because the table has vertically merged cells error at For j = 1 To tbl.Rows(i).Cells.count Code:
Sub CellMerge() Dim doc As Document Dim tbl As Table Dim nestedTbl As Table Dim i As Integer Dim j As Integer ' Set the document to the active document Set doc = ActiveDocument ' Ensure there is at least one table in the document If doc.Tables.Count > 0 Then ' Reference the first table Set tbl = doc.Tables(1) ' Loop through each row in the main table For i = 1 To tbl.Rows.Count ' Loop through each cell in the row For j = 1 To tbl.Rows(i).Cells.Count ' Check if the cell contains a nested table If tbl.Rows(i).Cells(j).Tables.Count > 0 Then ' Reference the nested table Set nestedTbl = tbl.Rows(i).Cells(j).Tables(1) ' Perform operations on the nested table ' Example: Print the number of rows in the nested table Debug.Print "Nested Table in Row " & i & ", Cell " & j & " has " & nestedTbl.Rows.Count & " rows." ' Example: Merge cells in the nested table if needed If nestedTbl.Rows.Count > 1 Then nestedTbl.Cell(1, 1).Merge nestedTbl.Cell(1, 2) End If End If Next j Next i Else MsgBox "No tables found in the document." End If End Sub Please review the code and am attaching new attachment for the reference please review once. Any other idea or suggestion would be highly appreciated. Manually merging each cells in a table was taking more time, your help is highly appreicated. PLEASE REVIEW THE ATTACHMENT WITH THE NAME TEST2 THANKS IN ADVANCE............ Last edited by ranjan; 05-03-2025 at 08:45 PM. |
![]() |
Tags |
table borders |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
tomohawk | Excel | 2 | 02-03-2023 08:24 AM |
![]() |
Eriks | Word | 9 | 04-19-2019 06:18 PM |
![]() |
BartS | Word Tables | 2 | 08-16-2016 04:10 AM |
TOC Formatting Issue | Caroline | Word | 1 | 03-15-2011 01:59 PM |
TOC Formatting Issue | Angstromm | Word | 0 | 09-22-2010 11:49 AM |