![]() |
#1
|
|||
|
|||
![]()
Need Word VBA code:
In a word document tables contains only text and blank cells in the last row of the table and to the immediate table of second row having only text and blank cells then it should be tagged ## at the begining of that immediate table Document only contains table, i need to check all tables in a document. I tried the below code, but it is not working could you please anyone help me... For reference PFA. Code:
Sub Spliting() Dim wdApp As Object Dim wdDoc As Object Dim wdTable As Object Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open("path_to_word_document.docx") For Each wdTable In wdDoc.Tables If wdTable.Rows.Count > 1 Then If IsTableTextAndEmptyLastRow(wdTable) And IsTableTextAndEmptyLastRow(wdTable.Next)) Then wdDoc.Content.InsertAfter "##" End If End If Next wdTable wdDoc.Close savechanges:=True wdApp.Quit Set wdTable = Nothing Set wdDoc = Nothing Set wdApp = Nothing End Sub Function IsTableTextAndEmptyLastRow(table As Object) As Boolean Dim lastRow As Object Dim cell As Object Set lastRow = table.Rows(table.Rows.Count) For Each cell In lastRow.Cells If cell.Range.Text <> " " Then IsTableTextAndEmptyLastRow = False Exit Function End If Next cell IsTableTextAndEmptyLastRow = True End Function |
![]() |
Tags |
spitting, word formatting lost |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
laith93 | Word VBA | 3 | 12-10-2021 03:22 PM |
Table Help: lock table structure and collapse/expand parts of table | bsafra1 | Word | 0 | 11-06-2018 03:01 AM |
![]() |
kevinbradley57 | Word VBA | 9 | 09-21-2017 04:58 PM |
![]() |
CTNAM | Word Tables | 1 | 04-11-2016 04:14 AM |
![]() |
donaldadams1951 | Word VBA | 4 | 02-04-2015 03:54 PM |