Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting WordArt in a Report 1

Status
Not open for further replies.

noHandlebars

Technical User
Jun 25, 2008
46
US
In this report, there is word art located in the headers of many pages but not every page of the report. It needs to be deleted. Is there a simple way to delete all the word art from the headers? Or do a test on each page to determine if that page has word art on it, then delete it somehow?
 




"delete all the word art from the headers"

IF the Word Art is in HEADERS, the page does not matter. These objects are in the Headers Collection. You could do something like this, depending on the TYPE OF SHAPE...
Code:
Sub test()
    Dim hdr As HeaderFooter, ish As InlineShape
    For Each hdr In ThisDocument.Sections(1).Headers
        For Each ish In hdr.Range.InlineShapes
            ish.Delete
        Next
    Next
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Since WordArt is created as a Shape object rather than as an InlineShape, I'd approach this a bit differently:
Code:
Sub Test()
Dim Hdr As HeaderFooter, Shp As Shape
For Each Hdr In ThisDocument.Sections(1).Headers
  For Each Shp In Hdr.Shapes
    If Shp.Type = msoTextEffect Then Shp.Delete
  Next
Next
End Sub
Cheers

[MS MVP - Word]
 
And even more robust:
Code:
Sub Test()
Dim Hdr As HeaderFooter, Shp As Shape, iShp As InlineShape, xShp
For Each Hdr In ThisDocument.Sections(1).Headers
  For Each Shp In Hdr.Shapes
    If Shp.Type = msoTextEffect Then Shp.Delete
  Next
  For Each iShp In Hdr.Range.InlineShapes
    If iShp.Type = wdInlineShapePicture Then
      xShp = iShp.Range.Duplicate
      xShp.ConvertToShape
      If xShp.Type = msoTextEffect Then iShp.Delete
      xShp.Delete
    End If
  Next
Next
End Sub
Cheers

[MS MVP - Word]
 
It seems like that should work, but it isnt. Any ideas why it wouldn't be working?
 
Since you stated that some pages have wordart and some don't, it would seem logical to believe that your document has sections.

All of the above codes work for only the first section.
 
Yeah that makes sense, how would you fix that code to include all sections?
 




Code:
Sub Test()
Dim Hdr As HeaderFooter, Shp As Shape, iShp As InlineShape, xShp, stn as section
for each stn in thisdocument.sections
 For Each Hdr In stn.Headers
  For Each Shp In Hdr.Shapes
    If Shp.Type = msoTextEffect Then Shp.Delete
  Next
  For Each iShp In Hdr.Range.InlineShapes
    If iShp.Type = wdInlineShapePicture Then
      xShp = iShp.Range.Duplicate
      xShp.ConvertToShape
      If xShp.Type = msoTextEffect Then iShp.Delete
      xShp.Delete
    End If
  Next
 Next
next
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
For some reason it is still not working. I'm not sure if it matters or not, but the word art's layout is more in the background of the text then in the usual header position. It is not located in the little dashed line box for the header/footer.
 



In the header or footer, can you SELECT the object?

In the body of the document, can you SELECT the object?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi noHandlebars,

The code works - I tested it before posting. Placement before/behind text is inconsequential, provided it's in the header.

Are you sure the objects are WordArt objects (ie can you edit them as WordArt objects)? Are there any other shape objects (eg Autoshapes, pictures) in the header? If so, have any of these been grouped with your WordArt object?

Cheers

[MS MVP - Word]
 
You definitely select the object in the header/footer. The objects ca be edited as WordArt Objects. There is no other shapes in the header. The code macropod provided still is not working. I am not sure what's wrong with it.
 
Hi noHandlebars,

Simply saying the code isn't working isn't very helpful.

Here's a slightly different approach, tested with Word 2000. The main differences are:
1. the code runs against the ActiveDocument instead of the document/template in which the module is located
2. if the header under consideration is linked to a previous one, it is skipped (on the basis that the previous header will be tested in its own right) and
3. the inlineshape testing & conversion to shape is done before the shape testing & deletion.
Thus, the code should be more flexinble and run more quickly.
Code:
Sub DelHdrWordArt()
Dim Sctn As Section, Hdr As HeaderFooter, Shp As Shape, iShp As InlineShape, xShp
For Each Sctn In ActiveDocument.Sections
  For Each Hdr In Sctn.Headers
    If Not Hdr.LinkToPrevious Then
      For Each iShp In Hdr.Range.InlineShapes
        If iShp.Type = wdInlineShapePicture Then
          Set xShp = iShp.ConvertToShape
          If xShp.Type <> msoTextEffect Then xShp.ConvertToInlineShape
        End If
      Next iShp
      For Each Shp In Hdr.Shapes
        If Shp.Type = msoTextEffect Then Shp.Delete
      Next Shp
    End If
  Next Hdr
Next Sctn
End Sub
Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top