View Single Post
 
Old 11-23-2019, 01:57 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Notwithstanding that your 'master' document should be a template from which new documents are created rather than saved with a new name, you need to run your code with a batch process that opens all the appropriate documents and runs your code. You should also introduce some error handling to at least ensure that there are four tables or more in the documents. The following will work as a custom process with Document Batch Processes which will handle the files and folders.

Code:
Function ProcessTables(oDoc As Document) As Boolean
Dim oTbl As Table
Dim Row As Integer
Dim Col As Integer
Dim oCell As Range
Dim strCellText As String
    On Error GoTo err_Handler

    If oDoc.Tables.Count > 3 Then
        Set oTbl = oDoc.Tables(3)
        For Row = 1 To oTbl.Rows.Count
            For Col = 1 To oTbl.Columns.Count
                Set oCell = oTbl.Cell(Row, Col).Range
                oCell.End = oCell.End - 1
                strCellText = oCell.Text
                Set oCell = oDoc.Tables(4).Cell(2, 3).Range
                oCell.End = oCell.End - 1
                If Trim(strCellText) = "X" Then
                    oCell.Text = "nailed it"
                    Exit For
                    Exit For
                End If
            Next Col
        Next Row
        ProcessTables = True
    End If
lbl_Exit:
    Exit Function
err_Handler:
    ProcessTables = False
    Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote