Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Deleting shapes in headers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roderick O'Regan - 30 Aug 2005 13:14 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.