I have a template with a shape in the header. At times I need to
delete that shape if it is going to be used with pre-printed
letterheads.
At present, I use:
Selection.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.SelectAll
Selection.Delete
As this shape is the only one in the headers/footers it does what I
need.
However, now I need to have a logo (also a shape) in the footer which
needs to stay there all the time, even when the header shape is
deleted.
As the above routine deletes all the shapes, irrespective of their
header/footer location, could someone tell me, please, if there is a
way to delete just the header shape and leave the footer one intact?
Regards
Roderick
Greg - 30 Aug 2005 13:33 GMT
Roderick,
I won't go on about how you should have a template for pre-printed
letterhead and a template for this and a template for that ;-)
Try:
Sub ScratchMacro()
Dim oRng As Range
For Each oRng In ActiveDocument.StoryRanges
Select Case oRng.StoryType
Case Is = 6, 7, 10
oRng.ShapeRange.Delete
Case Else
'Do nothing
End Select
Next
End Sub
John - 30 Aug 2005 14:22 GMT
Hello Roderick,
I guess you could loop through the Shapes and delete if it is not the logo.
The key is to identify the logo, which you could do by name, position, ID,
size etc. So, something like (this does the whole document and looks for
the size of the shape, but you can easily changes these):
Sub DeleteHeaderShapes()
Dim wDoc As Word.Document
Dim shps As Shapes
Set wDoc = ActiveDocument
For x = 1 To wDoc.Sections.Count
If wDoc.Sections(x).Headers(wdHeaderFooterPrimary).Shapes.Count > 0
Then
Set shps =
wDoc.Sections(x).Headers(wdHeaderFooterPrimary).Shapes
For i = shps.Count To 1 Step -1
'Change this section depending on known criteria
If shps(i).Width > MillimetersToPoints(50) _
And shps(i).Height < MillimetersToPoints(10) Then
shps(i).Delete
End If
Next i
End If
Next x
End Sub
Best regards
John
>I have a template with a shape in the header. At times I need to
> delete that shape if it is going to be used with pre-printed
[quoted text clipped - 19 lines]
>
> Roderick
Roderick O'Regan - 31 Aug 2005 00:07 GMT
Greg: Yeah. OK. OK. You're right. I know. But...just this once! Thanks
for your help.
John: Thanks also for your help.
Will try both methods and see which might fit the circumstances. But
it's great for me to learn how to use two diametrically opposite
solutions to resolve the problem.
Regards
Roderick
>Hello Roderick,
>
[quoted text clipped - 54 lines]
>>
>> Roderick