PDA

View Full Version : Placing image in upperright corner with VBA



Emperor
07-12-2013, 12:39 AM
Hi all,

I am creating a template in which users can pick an image which needs to be displayed/placed in the upperright corner of the page. (if possible in the header)
My problem is that the upperright corner with VBA is limited by the pagemargins, not by the paper.

Is there a way to do place it in the correct positition?



Dim link
link = Extern & "afbeeldingen\Rapportage\" & ComboBox3.Value

ActiveDocument.Bookmarks("afbeelding").Select
ActiveDocument.Shapes.AddPicture FileName:=link, LinkToFile:=False, SaveWithDocument:=True, Left:=0, Top:=0
With ActiveDocument.Shapes(1)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Left = InchesToPoints(0)
.Top = InchesToPoints(0)
End With


Thanks in advance!

Mathijs.

Emperor
07-18-2013, 02:24 AM
Nobody has an idea? not even a clue?

I'm quite stuck so any help is welcome!

fumei
07-19-2013, 03:56 PM
It is not that difficult...IF you set things up correctly.
Sub PutImageInheader()
ActiveDocument.Sections(1).Headers(1).Range.InlineShapes.AddPicture _
FileName:="c:\Gerry Pic\SmallLeon.jpg", _
LinkToFile:=False, SaveWithDocument:=True
End Sub

This puts the image file at the top right corner IN THE HEADER (which is what you asked for).

It ONLY works because the header:
1. has no other content
2. is set up with a appropriate style (right indent moved to the right the amount you want, and the paragraph right-aligned)

You should use styles anyway. So if you have the paragraph in the header set up correctly, just pop the image in. Note that it is an InlineShape - NOT a shape.