Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2023, 12:46 PM
ranjan ranjan is offline Table Spitting Windows 10 Table Spitting Office 2019
Advanced Beginner
Table Spitting
 
Join Date: May 2021
Posts: 77
ranjan is on a distinguished road
Default Table Spitting

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
Attached Files
File Type: docx TEST.docx (64.0 KB, 5 views)
Reply With Quote
Reply

Tags
spitting, word formatting lost



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table Spitting Convert table of contents to table format and preserving dynamic property of fields 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
Table Spitting 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
Table Spitting How to repeat table header of table within table CTNAM Word Tables 1 04-11-2016 04:14 AM
Table Spitting Move table cell contents from one table to another table or cell in same table donaldadams1951 Word VBA 4 02-04-2015 03:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:40 AM.


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