PDA

View Full Version : Solved: Image in Footer behind text



babsiee
10-28-2012, 01:31 PM
Hi Guys, I have two questions. Hope you guys can help me!

1. Image behind text in footer
I have made a macro that adds images in the header and footer of my word document. However, I would like my image in the footer to go behind the text. How can I do this in my macro? What code should I add? Hope you guys can help me.

2. Fullsize image
Is there a possibility that my images in the header and footer will not resize automaticly? I have made an image that is as width as my paper so it would be nice if the image will be inserted at it's original size.

Thank you so much for reading. Looking forward to your response.

This is my code until now:


Sub TITLE()
'
' TITLE Macro
'
'

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader 'headers van de pagina's 2 en verder
Selection.InlineShapes.AddPicture FileName:= _
"C:\header-image.jpg", LinkToFile:= _
False, SaveWithDocument:=True

WordBasic.ViewFooterOnly 'Footers van de pagina's 2 en verder
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).InlineShapes.AddP icture FileName:="C:\footer-image.jpg", LinkToFile:= _
False, SaveWithDocument:=True

Dim asection As Section
Set asection = Selection.Sections(1)
With asection
With .PageSetup
End With

'header pagina 1
.Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture FileName:="C:\header-image.jpg", LinkToFile:= _
False, SaveWithDocument:=True


'footer pagina 1

.Footers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture FileName:="C:\footer-image.jpg", LinkToFile:= _
False, SaveWithDocument:=True


End With
End Sub

macropod
10-29-2012, 08:49 AM
Your code appears to be trying to insert the header content twice - once at the current location and again on the first page. It is not clear why you would want to do that, especially as you have no code to test whether you have the correct page setup or the correct page selected. If the images are meant to appear on every page, instead of just the first page of the current Section, change 'wdHeaderFooterFirstPage' to 'wdHeaderFooterPrimary'; otherwise you really should add the required code to ensure the correct pagesetup.

It seems to me your code could be reduced to:Sub TITLE()
Application.ScreenUpdating = False
Dim Shp As Shape
With Selection.Sections(1)
Set Shp = .Headers(wdHeaderFooterFirstPage).Shapes.AddPicture _
(FileName:="C:\header-image.jpg", LinkToFile:=False, SaveWithDocument:=True)
With Shp
.WrapFormat.Type = wdWrapBehind
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(5.75)
End With
Set Shp = .Footers(wdHeaderFooterPrimary).Shapes.AddPicture _
(FileName:="C:\footer-image.jpg", LinkToFile:=False, SaveWithDocument:=True)
With Shp
.WrapFormat.Type = wdWrapBehind
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(4.5)
End With
End With
Set Shp = Nothing
Application.ScreenUpdating = True
End Sub
You will need to supply your own image widths.

PS: When posting code, please use the VBA tags.

babsiee
10-31-2012, 07:31 AM
Thanks, this worked great!! :) Still getting the hang of the macro's, so it was really helpfull to read your anwser and to narrow down the code.

Sorry for not using the VBA tags, will remind it for the next posts.