View Single Post
 
Old 05-16-2018, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

The following macro run as a custom process from
http://www.gmayor.com/document_batch_processes.htm
to handle the folder allocations will change the text in the cell to that indicated in the function. It assumes that if a 2x2 table exists in any header in the document it will be processed.
Code:
Function UpdateHeader(oDoc As Document) As Boolean
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oTable As Table
Dim oCell As Range
    On Error GoTo err_Handler
    For Each oSection In oDoc.Sections
        For Each oHeader In oSection.Headers
            If oHeader.Exists = True Then
                If oHeader.Range.Tables.Count = 1 Then
                    Set oTable = oHeader.Range.Tables(1)
                    If oTable.Rows.Count = 2 And oTable.Columns.Count = 2 Then
                        Set oCell = oTable.Cell(1, 1).Range
                        oCell.End = oCell.End - 1
                        oCell.Text = "The new text for the cell"
                    End If
                End If
            End If
        Next oHeader
    Next oSection
    UpdateHeader = True
lbl_Exit:
    Set oSection = Nothing
    Set oHeader = Nothing
    Set oTable = Nothing
    Set oCell = Nothing
    Exit Function
err_Handler:
    UpdateHeader = False
    GoTo 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