Finding and deleteing WordArt in Headers

  • Thread starter Roderick O'Regan
  • Start date
R

Roderick O'Regan

I have a WordArt graphic in each section header of a document which I
want to sequentially delete.

There are other graphics in each header and therefore I need to be
specific in what I choose.

I've got the following piece of coding from the VBA help and trying to
adapt it to do this:

Set myDocument = ActiveDocument
For Each s In myDocument.Shapes
If s.Type = msoTextEffect Then
s.TextEffect.PresetTextEffect = msoTextEffect1
End If
Next

Naturally, I would have to go into the header in the first section,
delete it then move on to the next section, and so on.

This I think I can do. Its the identifying and deleting an object as
being WordArt in the header which I cannot grasp.

Can anyone help, please?

Roderick O'Regan
 
H

Helmut Weber

Hi Roderick,

have a look at this one:

Sub Test444091()
Dim rTmp As Range
Dim oshp As Shape
Set rTmp =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
For Each oshp In rTmp.ShapeRange
MsgBox oshp.Type
Next
End Sub

Beware of linebreaks by the newsreader.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Roderick O'Regan

Thanks Helmut for the tip.

As the document had a different first page section I changed your
coding to reflect that it was a wdHeaderFooterFirstPage and it
identified the WordArt Graphic.

I then changed the coding to select the graphic and delete it.

This it did. I then told it to go to the next section, look once more
for the WordArt graphic. It certainly did appear to go to the next
sectrion but then it all turned into a ball of string which I cannot
seem to unravel.

I keep getting run-time error 7 "out of memory". I look for the
instructions about what could be wrong. Nothing I can see.

Start changing all sorts of things and now its a great knotted ball of
string.

Any ideas why the whole thing is falling over, please?

Roderick
 
R

Roderick O'Regan

Thanks Helmut for the advice

Here's the code adapted from that link you pointed out to me which now
allows me to loop through all storyRanges and delete the
AutoTextgraphic saying "DRAFT":

Public Sub DeleteDraft()
Dim rngStory As Word.Range
Dim lngJunk As Long
Dim oShp As Shape
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
'Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case rngStory.StoryType
Case wdEvenPagesHeaderStory, wdFirstPageHeaderStory,
wdPrimaryHeaderStory
If rngStory.ShapeRange.Count > 0 Then
For Each oShp In rngStory.ShapeRange
If oShp.Type = msoTextEffect Then
oShp.Select
oShp.Delete
End If
Next
End If
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub

My thanks to Doug Robbins, Greg Maxey, Peter Hewett and Jonathan West
for writing the article and supplying the code and to you Helmut for
knowing about it and pointing me to it.

One interesting this is that in the original code the following is
written:
Case 6, 7, 8, 9, 10, 11

I had to convert this to:
Case wdEvenPagesHeaderStory, wdFirstPageHeaderStory,
wdPrimaryHeaderStory
to enable me to choose the ones to be affected.

Are there comparison lists somewhere (they don't seem to be in VBA
Help) which tell you which figure represents each WdStoryType? One
certainly cannot apply the list in VBA Help to the list 1,2,3, etc. by
starting at the top and working downwards.

Likewise in the msoShapeTypes referred to above, WordArt shapes are
designated as 15.

Thanks again, though.

Roderick.
 
H

Helmut Weber

It is hell,

but you made it. :)
Congratulations.

For the rest, your are more advanced than I am.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Roderick,

in the VBA-editor, goto the object browser,
shortcut is [F2],
from the listbox in the top left hand corner
select "Word",
in the combobox below it,
type "storytype".

Click the spyglass, or whatever it called in english.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top