Consulting

Results 1 to 3 of 3

Thread: Placing image in upperright corner with VBA

  1. #1
    VBAX Regular
    Joined
    Dec 2009
    Posts
    15
    Location

    Question Placing image in upperright corner with VBA

    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.

  2. #2
    VBAX Regular
    Joined
    Dec 2009
    Posts
    15
    Location
    Nobody has an idea? not even a clue?

    I'm quite stuck so any help is welcome!

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    It is not that difficult...IF you set things up correctly.
    [VBA] Sub PutImageInheader()
    ActiveDocument.Sections(1).Headers(1).Range.InlineShapes.AddPicture _
    FileName:="c:\Gerry Pic\SmallLeon.jpg", _
    LinkToFile:=False, SaveWithDocument:=True
    End Sub[/VBA]

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •