Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2015, 11:48 AM
sanpedro sanpedro is offline Macro to select an { includepicture } field code and format the picture behind text and 100% scale Windows 8 Macro to select an { includepicture } field code and format the picture behind text and 100% scale Office 2007
Novice
Macro to select an { includepicture } field code and format the picture behind text and 100% scale
 
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
  #2  
Old 03-29-2015, 11:18 PM
gmayor's Avatar
gmayor gmayor is offline Macro to select an { includepicture } field code and format the picture behind text and 100% scale Windows 7 64bit Macro to select an { includepicture } field code and format the picture behind text and 100% scale Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Once you change an inline shape to a shape it is no longer an inline shape so you cannot process it as such. The following should work

Code:
Sub fixLetterHead()
Dim oInlineShape As InlineShape
Dim oShape As shape
    For Each oInlineShape In Selection.InlineShapes
        Set oShape = oInlineShape.ConvertToShape
        With oShape
            .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
            .RelativeVerticalPosition = wdRelativeVerticalPositionPage
            .Top = 0
            .Left = 0
            .WrapFormat.Type = wdWrapBehind
            .ScaleHeight 1, True
            .ScaleWidth 1, True
        End With
    Next oInlineShape
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-30-2015, 10:12 AM
sanpedro sanpedro is offline Macro to select an { includepicture } field code and format the picture behind text and 100% scale Windows 8 Macro to select an { includepicture } field code and format the picture behind text and 100% scale Office 2007
Novice
Macro to select an { includepicture } field code and format the picture behind text and 100% scale
 
Join Date: Feb 2015
Posts: 4
sanpedro is on a distinguished road
Smile

Thank you very much! this works perfectly. i have amended it slightly by having a Exit For statement at the end of the for loop to only convert the first picture it finds. probably not the best way to do it but it works well so far.

Thank you
Reply With Quote
  #4  
Old 03-30-2015, 10:50 PM
gmayor's Avatar
gmayor gmayor is offline Macro to select an { includepicture } field code and format the picture behind text and 100% scale Windows 7 64bit Macro to select an { includepicture } field code and format the picture behind text and 100% scale Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Exit For will do the job or you could lose the loop and change to

Code:
Set oInlineShape = Selection.InlineShapes(1)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
formatting, picture

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to select an { includepicture } field code and format the picture behind text and 100% scale Using IncludePicture and MailMerge to insert picture Elena Mail Merge 25 02-06-2022 05:35 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Macro to select an { includepicture } field code and format the picture behind text and 100% scale VBA code for Microsoft Word macro — select text and insert footnote ndnd Word VBA 10 01-06-2015 01:47 PM
Macro to select an { includepicture } field code and format the picture behind text and 100% scale Is it possible to not select all text upon entering a form field? pruppert Word 6 07-16-2012 08:01 PM
Word Editing Text for Picture format sarun5 Word 2 05-27-2009 11:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:28 PM.


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