View Single Post
 
Old 05-17-2018, 07:46 AM
catflap's Avatar
catflap catflap is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Aug 2015
Location: UK
Posts: 72
catflap is on a distinguished road
Default Insert graphic file and position at top left corner of page

Hi

Hopefully this is a straightforward request, but getting it exactly right has had be scratching me head a bit.

I want to insert an image file into a document, positioned at top left (ie 0,0 from the page) and resize it to the whole page, then set it's wrapping to behind and set it so it does not move with text.

I have this cobbled together so far:

Code:
Sub testaddshape()
        
        Dim myshape As Shape
           
        Set myshape = ActiveDocument.Shapes.AddPicture(FileName:="c:\test\overlay.png", _
            LinkToFile:=False, _
            SaveWithDocument:=True, _
            Left:=-ActiveDocument.PageSetup.LeftMargin, _
            Top:=0, _
            Width:=ActiveDocument.PageSetup.PageWidth, _
            Height:=ActiveDocument.PageSetup.PageHeight)
        
            With myshape
                .ZOrder msoSendBehindText
                .WrapFormat.Type = wdWrapBehind
                .LockAnchor = True
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
                .RelativeVerticalPosition = wdRelativeVerticalPositionPage
            End With
     
End Sub
The overlay.png is just an A4-sized image with a rectangle on it which shows me a window position, so I can line up a letter. It looks like this:



Currently when I run the code, I can get the size right, set to 'behind' wrapping, and position to the left correctly. What I can't do is set the height so it's right at the top of the page. Currently I get this:



Hopefully you can see the top of the graphic will not go any higher than my top margin.


Can anyone help me just finish this off so it goes right to the top?

I've seen another post on the forum here: https://www.msofficeforums.com/word-...0-vba-tip.html

... where the graphic is positioned in the header - I could not seem to adapt this to my needs and I'd rather it stay on the page if possible anyway.

Thanks in advance for any help.
Reply With Quote