View Single Post
 
Old 11-12-2018, 08:32 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,184
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can't wrap text around an inline shape - it needs to be a floating shape. So you need to convert it to a shape if you want the text wrap setting. Shapes are not bothered with paragraph alignment so that probably won't be needed unless you are also putting text in the header.
Code:
Sub AddImageToHeader()
  Dim SrcePath As String, headerPic As InlineShape, aShp As Shape
  SrcePath = "S:\DocBase\Document Templates\Macros\New Macros Nov 2018\Letterhead.jpg"
  Set headerPic = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes.AddPicture(SrcePath)
  Set aShp = headerPic.ConvertToShape
  With aShp
    .LockAspectRatio = msoTrue
    .Width = CentimetersToPoints(21)
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
    .Top = 0
    .Left = 0
    .WrapFormat.Type = wdWrapBehind
  End With
End Sub
Also, you can't use ThisDocument because it refers to the document where the macro resides (ie the template) rather than the document you thought you were running the macro on. While you are doing testing in the template you won't notice any problems but you won't get the result you are looking for once you try to run the macro on a document rather than the template.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote