Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2018, 03:33 AM
marafubu marafubu is offline Batch change header text which is in a table Windows 10 Batch change header text which is in a table Office 2013
Novice
Batch change header text which is in a table
 
Join Date: May 2018
Posts: 1
marafubu is on a distinguished road
Post Batch change header text which is in a table

Hello,



I have around 200 documents with the same header - it's a 2x2 table with some text in every cell. I need to change the text in upper left cell to new text in every document.

I found solutions to change header in multiple documents using macro, but none of them involved tables as headers.

Thanks in advance for your help
Reply With Quote
  #2  
Old 05-16-2018, 04:52 AM
gmayor's Avatar
gmayor gmayor is offline Batch change header text which is in a table Windows 10 Batch change header text which is in a table 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

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
Reply

Tags
header, macro, table



Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch replace Header and Footer and QuickStyle Artmax Word VBA 14 01-11-2024 05:36 PM
Table of contents with section breaks (text in table in header) Dmonk Word 2 05-23-2017 04:29 AM
Batch change header text which is in a table How to batch change hyperlink paths in Word 2000 alsearsa Word 2 01-26-2016 02:32 PM
Can't change table background color in the header in Microsoft Word 2011 simeon1 Word 0 10-13-2014 11:07 AM
Batch change header text which is in a table Need to change text in header to next Heading 1 Kanith Word 1 06-14-2011 03:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:06 PM.


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