Picture alignment in header

L

Listrom

Being an amateur, I would greatly appreciate some urgent help, as I might
have promised my dear users to make something a bit too advanced for me…:
Word 2003 – I’m trying to make a template where I have defined “our†styles,
made a automatic update of TOC, and in a dialog box they are supposed to type
in title and date of the document, and they should also choose a picture
(among four) to bee placed in the header, behind the text on the front page.
So far so good, except the alignment of the picture. I am trying to center
it, but it doesn’t work. I am sure it is just some detail I just have not
understood. Code is enclosed without all my experiments with
alignment….Strange, because it actually worked for a while for me, but not
for my testuser, and later not for me either. The picture ends up
rightaligned, partly outside the page. I know I changed to a different
normal.dot, could this have something to say? Could it be other settings
that would override my code?

ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageHeader
ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range,
FileName:= _
"K:\Maler\Bakgrunnsbilder\Oker_fyr.bmp" _
, LinkToFile:=False, SaveWithDocument:=True, Left:=15, Top:=20,
Width:=565.2, Height:=800.35).ZOrder msoSendBehindText
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

So, 1 – how do I centeralign the picture in the code, and how do I make sure
this work for users with different settings?
 
S

Shauna Kelly

Hi Listrom

Word can display a picture as floating or inline. For the difference, see
http://www.word.mvps.org/FAQs/DrwGrphcs/InlineVsFloating.htm.

What your code is doing is creating a floating object (a Shape is a floating
object), anchored to the Selection.

But it sounds like you might want to have the picture in-line and centred.
If you do need it in-line, then I would modify the Header style to make it
centred, and then paste your picture into it.

So, I suggest that you experiment without using code to work out what you
need. Then choose whichever of the following you need.


Sub InsertInLinePictureInFirstPageHeader()

Dim oILS As Word.InlineShape

Set oILS = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Range.InlineShapes.AddPicture( _
FileName:="K:\Maler\Bakgrunnsbilder\Oker_fyr.bmp", _
LinkToFile:=False, _
SaveWithDocument:=True)

With oILS
.Width = 565.2
.Height = 800.35
End With

End Sub


Sub InsertFloatingPictureInFirstPageHeader()

Dim oShape As Word.Shape
Dim dblLeft As Double

Set oShape = ActiveDocument.Shapes.AddPicture( _
Anchor:=ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range,
_
FileName:="K:\Maler\Bakgrunnsbilder\Oker_fyr.bmp", _
LinkToFile:=False, _
SaveWithDocument:=True)

'Size and position the shape
With oShape
.Top = 20 '20 points down from the range of the header
.Width = 565.2
.Height = 800.35
.ZOrder msoSendBehindText
End With

'Work out how to centre the image horizontally
With ActiveDocument.PageSetup
dblLeft = (.PageWidth - .LeftMargin - .RightMargin - oShape.Width) /
2
End With

'Position the image horizontally
oShape.Left = dblLeft

End Sub




Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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