Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2017, 02:56 PM
thuizt thuizt is offline Image absolute position relative to page Windows 10 Image absolute position relative to page Office 2016
Novice
Image absolute position relative to page
 
Join Date: Jul 2017
Posts: 3
thuizt is on a distinguished road
Default Image absolute position relative to page

Hello,



Have a macro to insert an image in a header.
This image must be relative to the page and not column and/or paragraph as it seems to do.
How to fix this ?

Hmmm, should I first set picture behind text to do this ??

regards.

Code follows.
Reply With Quote
  #2  
Old 07-31-2017, 04:39 PM
macropod's Avatar
macropod macropod is offline Image absolute position relative to page Windows 7 64bit Image absolute position relative to page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It would be helpful if you posted the code... Without it, it's impossible to know what change might be needed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-01-2017, 12:33 AM
thuizt thuizt is offline Image absolute position relative to page Windows 10 Image absolute position relative to page Office 2016
Novice
Image absolute position relative to page
 
Join Date: Jul 2017
Posts: 3
thuizt is on a distinguished road
Default

Code:
Sub ImageInHeaderFooter()

    Set header = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture( _
        FileName:="\\URL2Image.jpg", _
        SaveWithDocument:=True _
    )
    
    With header
        .Left = CentimetersToPoints(-0.5)
        .Top = CentimetersToPoints(0.7)
        .Width = CentimetersToPoints(8.2)
        .Height = CentimetersToPoints(1.74)
    End With
    
    
    Set footer = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Shapes.AddPicture( _
        FileName:="\\URL2Image.jpg", _
        SaveWithDocument:=True _
    )

    With footer
        .Left = CentimetersToPoints(-2.8)
        .Top = CentimetersToPoints(25.6)
        .Width = CentimetersToPoints(21.8)
        .Height = CentimetersToPoints(2.47)
    End With


End Sub
What happens is that the image is set relative to column horizontally and relative to paragraph vertically. Setting the image "behind text"does not change this.

Any ideas ??

Thanks

Last edited by macropod; 08-01-2017 at 02:58 AM. Reason: Added code tags
Reply With Quote
  #4  
Old 08-01-2017, 03:21 AM
macropod's Avatar
macropod macropod is offline Image absolute position relative to page Windows 7 64bit Image absolute position relative to page Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You need to tell Word what to set the position relative to. Try something based on:
Code:
Sub ImageInHeaderFooter()
Application.ScreenUpdating = False
Dim Shp As Shape
With ActiveDocument.Sections(1)

    Set Shp = .Headers(wdHeaderFooterPrimary).Shapes.AddPicture( _
        FileName:="\\URL2Image.jpg", SaveWithDocument:=True)
    
    With Shp
        .LockAnchor = True
        .LockAspectRatio = True
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Left = CentimetersToPoints(-0.5)
        .Top = CentimetersToPoints(0.7)
        .Width = CentimetersToPoints(8.2)
    End With
    
    Set Shp = .Footers(wdHeaderFooterPrimary).Shapes.AddPicture( _
        FileName:="\\URL2Image.jpg", SaveWithDocument:=True)

    With Shp
        .LockAnchor = True
        .LockAspectRatio = True
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        .RelativeVerticalPosition = wdRelativeVerticalPositionPage
        .Left = CentimetersToPoints(-2.8)
        .Top = CentimetersToPoints(25.6)
        .Width = CentimetersToPoints(21.8)
    End With
    
End With
Application.ScreenUpdating = True
End Sub
Presumably, you'll need to adjust the .Left values. Note that I've omitted the .Height specifications. Assuming your images already have the correct aspect ratio, locking it before resizing either the .Height or .Width is sufficient.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-01-2017, 07:25 AM
thuizt thuizt is offline Image absolute position relative to page Windows 10 Image absolute position relative to page Office 2016
Novice
Image absolute position relative to page
 
Join Date: Jul 2017
Posts: 3
thuizt is on a distinguished road
Default

Wauw,.....

Thanks very much Paul. Searched for it a long time and you just have it here.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlinks defaulting to absolute instead of relative!!! wdzambotti Word VBA 1 08-17-2015 09:03 PM
Fix data output position relative to page Al See Mail Merge 1 01-16-2014 04:13 PM
Image absolute position relative to page Set "Page" as default Image Layout Position (HELP BEFORE I GO NUTS!) cjt Word 6 05-26-2012 10:46 AM
Macro for absolute text box re-position hobbsbaboo PowerPoint 0 03-15-2012 01:44 AM
Image absolute position relative to page How To Get Image to be absolute center of slide mjg060468 PowerPoint 3 08-09-2010 02:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft