How do I delete a graphic in a header when writing a macro

H

Helmut Weber

Hi,

every possible graphical element in every possible header
of a multi section document of some hundred pages with
different headers of all kinds?

Or just a shape in the one and only header?

You may adapt this one, somewhat challenging:

http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm


Greetings from Bavaria, Germany

Helmut Weber, MVP, WordVBA

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

Mags at Mercer

Helmut, thank you for replying

I am not a programmer but I am a Word expert.

I have created a Word portrait report template, macro will insert landscape
page. I now need to delete the portrait graphic in the header and replace
with a landscape one. Both portrait and landscape graphics are saved as
autotext entries. Macro halts at:
Selection.HeaderFooter.Shapes("Group 1985") .Seclect

Can you help?
 
H

Helmut Weber

Hi Mags,

deleting and inserting isn't that much a problem.
Let's take the simplest case as an example,
disregarding screen flickering and speed,
and ask again, if there are unsolved questions.

Sub test678()
Dim oRng As Range
Set oRng = ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
' simple header
With oRng
.InlineShapes(1).Select
' in case the graphic is an inlineshape
' and it is the first inlineshape in the header
NormalTemplate.AutoTextEntries("MyLandscape").Insert _
Where:=Selection.Range, RichText:=True
' overwrite the inlineshape at the selection with a new one
End With
' the following may differ with your settings
With ActiveWindow.View
If .SplitSpecial <> wdPaneNone Then
.Parent.Panes(2).Close
End If
End With
With ActiveWindow.ActivePane
If .View.Type = wdNormalView _
Or .View.Type = wdOutlineView Then
.View.Type = wdPrintView
End If
End With
End Sub


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