Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
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: 51
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: http://www.msofficeforums.com/word-v...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
  #2  
Old 05-17-2018, 01:37 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 854
Guessed is on a distinguished road
Default

Try this one
Code:
Sub testaddshape()
  Dim myshape As Shape
    
  Set myshape = ActiveDocument.Shapes.AddPicture(FileName:="c:\test\overlay.png", _
     LinkToFile:=False, _
     SaveWithDocument:=True, _
     Left:=0, _
     Top:=0, _
     Width:=ActiveDocument.Sections(1).PageSetup.PageWidth, _
     Height:=ActiveDocument.Sections(1).PageSetup.PageHeight)
  
     With myshape
      .ZOrder msoSendBehindText
      .WrapFormat.Type = wdWrapBehind
      .LockAnchor = True
      .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
      .RelativeVerticalPosition = wdRelativeVerticalPositionPage
      .Left = 0
      .Top = 0
     End With
     
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 05-18-2018, 01:54 AM
catflap's Avatar
catflap catflap is offline Windows 7 64bit Office 2013
Advanced Beginner
 
Join Date: Aug 2015
Location: UK
Posts: 51
catflap is on a distinguished road
Default

Perfect!


Thanks for taking time to reply to this, it's really appreciated!


Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Doc printing tiny in left top corner margin waynefusion Word 6 11-02-2016 08:59 AM
insert .pdf (scanned file) as graphic eNGiNe Word 3 09-30-2015 11:40 PM
Circle visible in top left corner when saving page with a 'flow-text box as PDF Clover_Creative Word 0 05-30-2014 05:03 AM
Positioning Footer Graphic to Butt the Left Edge of the Page EXACTLY WLK Drawing and Graphics 3 09-26-2012 08:53 PM
Delete upper left corner of picture tom_94305 Word 1 08-03-2012 09:09 PM


All times are GMT -7. The time now is 08:41 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft