![]() |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
| 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 |
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 |
Need to change text in header to next Heading 1
|
Kanith | Word | 1 | 06-14-2011 03:35 PM |