View Single Post
 
Old 03-29-2015, 11:48 AM
sanpedro sanpedro is offline Windows 8 Office 2007
Novice
 
Join Date: Feb 2015
Posts: 4
sanpedro is on a distinguished road
Default Macro to select an { includepicture } field code and format the picture behind text and 100% scale

hi all,

i tried asking for a solution to this problem a while ago on the mail merge forum but after reading about this for quite a while i think the only choice is to use a macro after the merge,

https://www.msofficeforums.com/mail-...html#post77641

Essentially i need to include conditional full page letter head in my mail merge.

i have formatted the letterhead to by A4 in size but whenever i run the merge with this field code, {INCLUDEPICTURE ".../pictures/Logos/{MERGEFIELD "internal_party" }.jpg \*MERGEFORMAT \d } , the picture shinks within the margin ( i believe this is because merged pictures are in line with text).

Therefore i think i need a macro that selects the merged picture, sets the text wrapping to behind text, and then scale to 100%.

Code:
Sub fixLetterHead()

Dim shape As InlineShape
    Dim shapeRange As shapeRange
     
    ' iterate all selected shapes
    For Each shape In Selection.InlineShapes
        ' set with to 100 %
        shape.ScaleWidth = 100
        ' convert to shape to get a shaperange
        shape.ConvertToShape
        Set shapeRange = Selection.shapeRange
        ' position relative to the page
        shapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
        shapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionPage
        ' anchor to 0.0
        shapeRange.Top = 0
        shapeRange.Left = 0
        ' set to behind text
        shapeRange.WrapFormat.Type = wdWrapBehind
    Next

    If Selection.InlineShapes.Count > 0 Then
        Selection.InlineShapes(1).ScaleHeight = 100
        Selection.InlineShapes(1).ScaleWidth = 100
        
    Else
        Selection.shapeRange.ScaleHeight Factor:=100, _
          RelativeToOriginalSize:=msoCTrue
        Selection.shapeRange.ScaleWidth Factor:=100, _
          RelativeToOriginalSize:=msoCTrue
          Selection.shapeRange.WrapFormat.Type = wdWrapBehind
    End If

    


End Sub

ive pieced the above code together from online forums but its not working correctly. Also it only runs on selected pictures but i need to have it run for th eonly picture in the document.

the picture does correctly become behind text but it doesnt scale to 100%.

Am i close to having this working? if so, can someone please let me know how to amend my code? unfortunately i cant record macros to do this because word does not allow you to for pictures.

or if anyone has any other suggested solutions im all ears. Whatever the solution is it needs to be completely automatic.

Thank you in advance for any help.
Reply With Quote