![]() |
|
#1
|
|||
|
|||
![]()
Table formatting issue:
Need word VBA macro: Table cells has spitted into multiple cells within a cell that presented in …. Grid lines. I want to remove the …. Gridlines within that table border and merged that text which is separated with … Gridlines. Please see the attachment for the better understanding. Text within the complete table cells border has to be merged and removed the … grid lines border with the complete border of the cell. Your Help is Highly appreciated. |
#2
|
|||
|
|||
![]()
Gridlines or borders?
The way you remove gridlines (which do not print) is to merge cells. I am not sure you want to do that. To merge cells, select the cells and use the button to merge cells on the Table Layout tab. You can delete text you do not want. (I moved your post to the Word Tables forum.) |
#3
|
|||
|
|||
![]()
Manually removing gridlines (which do not print) is to merge cells.
There are so many tables in a document. Adjusting and merging each cells taking more time can we automate this task... Taking more time for merging the ...... grid lines within in the complete cell borders. Please review the attachment once. |
#4
|
||||
|
||||
![]()
Try:
Code:
Sub CellMerge() Application.ScreenUpdating = False Dim Tbl As Table, Cll As Cell For Each Tbl In ActiveDocument.Tables For Each Cll In Tbl.Range.Cells With Cll If .ColumnIndex < Tbl.Columns.Count Then If .Borders(wdBorderBottom).LineStyle = wdLineStyleNone And _ .Borders(wdBorderTop).LineStyle = wdLineStyleNone Then .Merge MergeTo:=Tbl.Cell(Row:=.RowIndex + 1, Column:=.ColumnIndex) .Merge MergeTo:=Tbl.Cell(Row:=.RowIndex - 1, Column:=.ColumnIndex) End If End If End With Next Next Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
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. |
#6
|
||||
|
||||
![]()
Well, you did say the document has multiple tables and you only supplied one example and you gave no indication that other tables might be formatted differently or that you didn't want the macro to process all of them. So that's all I had to code for.
If you want the code to only run on the selected table(s), simply change 'ActiveDocument' to 'Selection'. Given that you seem to have a variety of tables with different structures, you'll probably need a differernt macro for each structure.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
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 |