#1
|
|||
|
|||
Removing a Shape & Editing Header with Macro
Hi all,
I have a document which I receive on a daily basis and I have to edit the header each time. Is there a way I can first remove the shape around all of my text pages (excluding page 1), because while that shape is there, I can't really edit the header. I am using Word on a Mac. Once that is removed, is there a way I can take 4 different bits of information from Page 1, and paste that into specific places in the header? Can all this be done with a Macro? Appreciate the help, JH I have attached the document |
#2
|
|||
|
|||
I don't have a mac so not sure if this will work or not:
Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oSection As Section Dim lngIndex As Long, lngShape As Long For Each oSection In ActiveDocument.Sections For lngIndex = 1 To 3 For lngShape = oSection.Headers(lngIndex).Shapes.Count To 1 Step -1 oSection.Headers(lngIndex).Shapes(lngIndex).Delete Next lngShape Next lngIndex Next oSection lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
Thank you for this.
Yes, it does work, but it also removes the purpose-built line within the footer itself. I just wanted to remove the rectangle shape around the whole page. Also, it removes the border from around Page 1, which I wanted to keep. Can this be modified to take care of these two things? JH |
#4
|
|||
|
|||
Why are you attempting to treat the symptoms instead of the cause?
Fixing the template that these documents are created from would solve the problem permanently. |
#5
|
|||
|
|||
Quote:
JH |
#6
|
|||
|
|||
Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oSection As Section Dim oRng As Range Dim lngIndex As Long, lngShape As Long For Each oSection In ActiveDocument.Sections For lngIndex = 1 To 3 For lngShape = oSection.Headers(lngIndex).Range.ShapeRange.Count To 1 Step -1 oSection.Headers(lngIndex).Range.ShapeRange(lngShape).Delete Next Next Next lbl_Exit: Exit Sub End Sub |
#7
|
|||
|
|||
Quote:
It now works by leaving the line in the footer, but it still removes the shape from around Page 1. In fact, my real document has additional pages (attached), so is there a way to remove the shape from certain types of pages and to leave it on others? Have a look at the attached doc. JH |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Add Shape on every Header of each Section | Souriane | Word VBA | 5 | 12-08-2022 06:35 AM |
Adding text to the header and footer without removing all other content in the header and footer | digitalelise | Word VBA | 2 | 10-23-2019 02:58 AM |
Removing header from one page but not footer | smithurmann | Word | 1 | 12-15-2018 11:24 AM |
Removing header and footer on two pages in my document | oliboi | Word | 1 | 11-01-2016 05:27 PM |
selecting shape in header only | mhagi | Word VBA | 5 | 10-09-2015 01:10 AM |